Log in

View Full Version : Send auto reply to form field email address



stealthmode666
12-11-2008, 12:29 AM
How do I write php to read the email from a form and send the auto reply to the user who filled in their email address in the form in php?
This is the script I am Using.
At present it sends the data to me from the form and shows me the users e-mail addredd who filled it in and displays the thank-you page, but it also sends me the auto reply.
Here is my script

<?php
$to = ( isset ($_REQUEST['sendto']) ? $_REQUEST['sendto'] : "default 'to' email goes here" );
$from = ( isset ($_REQUEST['Email']) ? $_REQUEST['sendto'] : "default 'from' email goes here" ) ;
$name = ( isset ($_REQUEST['Member_Name']) ? $_REQUEST['Member_Name'] : "Default member name goes here" ) ;
$headers = "From: $from";
$subject = "Members Data From R.......com";

$fields = array();
$fields{"Member_Name"} = "Members Name";
$fields{"Email"} = "Members Email Address";
$fields{"....."} = "......";

$body = " You have received...:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

$headers2 = "From: me@somewhere.com";
$subject2 = "Thank-you for ..";
$autoreply = "Somebody from... Thank-you";

if($from == '') {print "You have..";}
else {
if($name == '') {print "You have..";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send){header( "Location: http://www.r....com/r../thankyou.html" );}
else
{print "We encountered ...@.....com"; }
}
}
?>

rangana
12-11-2008, 01:52 AM
On the first look, I think it's:


$from = ( isset ($_REQUEST['Email']) ? $_REQUEST['sendto'] : "default 'from' email goes here" ) ;


...which needs to be changed into Email

stealthmode666
12-11-2008, 09:08 AM
Thanks, I will try this in a few mins and see what happens

stealthmode666
12-11-2008, 09:35 AM
Hi there, got a page of errors on submit:
I changed the line below to what you suggested on the next line but got an error:
$from = ( isset ($_REQUEST['Email']) ? $_REQUEST['sendto'] : "default 'from' email goes here" ) ;
$from = ( isset ($_REQUEST['Email']) ? $_REQUEST['Email'] : "default 'from' email goes here" ) ;

Notice: Undefined index: homeowner in E:\domains\r\r....com\user\htdocs\r....\sform.php on line 170
plus about 15 more of these.

Warning: mail() [function.mail]: SMTP server response: 554 <me@r.........com>: Recipient address rejected: Relay access denied in E:\domains\r\r.......com\user\htdocs\r.......\sform.php on line 182
We encountered an error sending your mail, please notify webmaster@r......com

This is line 182 on my script:
$send = mail($to, $subject, $body, $headers);

Thanks for trying to help

stealthmode666
12-11-2008, 09:50 AM
Somehow the script is sending the form and the auto-reply to the same email.
I have used my email just now to send the form but it will be changed to the persons email of which it needs to go when all is working.
Do I need to add another variable that takes the form persons email which will send the auto-reply to them?
Not very good at php and really struggling with this one.

The form on submit I put a hidden field in which is this:
<input name="sendto" type="hidden" id="sendto" value="me@someone.com" />
I have used .js validation on server-side to check form before it can be submitted.

On my form this is the email input box of which I want the .php script to send the auto-reply to:
<input name="Email" type="text" id="Email" size="50" />
Hope this helps

rangana
12-12-2008, 06:14 AM
Know your mail server


Go to php.ini and set your mail server to that of the response on the first bullet. Alternatively, you can set it via ini_set():


ini_set('SMTP','your_smtp_protocol_here'); // Set your SMTP server



Know your SMTP port. Usually, the default is 25, but no harm when you ask.


Set it on your php.ini, or alternatively, do the same:


ini_set('smtp_port','25'); // Set your smtp port number



Hope that helps.