bubbafunk1 Posted March 20, 2010 Share Posted March 20, 2010 I have a form that when a user enters their email address and hits send an email is sent to their email address. I know how to send the reply to a predefined email address, but i want the email to be sent to the address in the $email = $_REQUEST['email']; here is my code in sendmail.php so far:- even though it does not work properly...... any help would be greatly appreciated. <?php $email = $_REQUEST['email']; $subject = "Your instant discount code"; $headers = "Reply-To: [email protected]\r\n"; $headers .= "Return-Path: [email protected]\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $message = "<html><body> Thank you for applying for an INSTANT DISCOUNT CODE. \n\n 1a2b3c4d5e \n\n is your discount code, please type it using lowercase letters at the checkout \r\n Thanks The Team <body></html>"; mail ("$email", "$headers" , "$message", "from: The Team"); if ( mail($email,$subject,$message,$headers) ) { header ("location: http://www.mydomain.co.uk/success.htm"); } else { header ("location: http://www.mydomain.co.uk/failed.htm"); } ?> Thanks in advance Link to comment https://forums.phpfreaks.com/topic/195905-simple-auto-respond/ Share on other sites More sharing options...
jskywalker Posted March 20, 2010 Share Posted March 20, 2010 I know how to send the reply to a predefined email address, but i want the email to be sent to the address in the $email = $_REQUEST['email']; Can you tell what the difference is between: 1) a predefined email address 2) the address in the $email = $_REQUEST['email']; Link to comment https://forums.phpfreaks.com/topic/195905-simple-auto-respond/#findComment-1029060 Share on other sites More sharing options...
bubbafunk1 Posted March 20, 2010 Author Share Posted March 20, 2010 1) a predefined email address would be when an email address is written in the code like this - mail ("[email protected]", "$headers" , "$message", "from: The Team"); 2) the address in the $email = $_REQUEST['email']; would be the email address that the user has put in the html form, their own email address. So when they press send the php code will take their email address from the $email = $_REQUEST['email']; and send an email right back to them. I have tried inserting $email into the code like so - mail ("$email", "$headers" , "$message", "from: The Team"); but it does not work... Link to comment https://forums.phpfreaks.com/topic/195905-simple-auto-respond/#findComment-1029189 Share on other sites More sharing options...
jskywalker Posted March 20, 2010 Share Posted March 20, 2010 i think you should verify if: $email = $_REQUEST['email']; really assigns the email-adress you expect... Link to comment https://forums.phpfreaks.com/topic/195905-simple-auto-respond/#findComment-1029220 Share on other sites More sharing options...
peter_anderson Posted March 20, 2010 Share Posted March 20, 2010 mail ("$email", "$headers" , "$message", "from: The Team"); should be: <?php //your other code here $headers = "Reply-To: [email protected]\r\n"; $headers .= "Return-Path: [email protected]\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $headers .= "From: [email protected]\r\n"; mail($email, $subject, $message, $headers); ?> Also, your if statement will cause the email to be sent twice. Link to comment https://forums.phpfreaks.com/topic/195905-simple-auto-respond/#findComment-1029223 Share on other sites More sharing options...
bubbafunk1 Posted March 21, 2010 Author Share Posted March 21, 2010 Thanks, Jskywalker and Peter, for your input. the form works fine now.... Do you know how i would write the email address to my database or a csv file on my server? Link to comment https://forums.phpfreaks.com/topic/195905-simple-auto-respond/#findComment-1029473 Share on other sites More sharing options...
jskywalker Posted March 21, 2010 Share Posted March 21, 2010 $file="some filename"; $f = fopen($file, "a"); fwrite($f, $email."\n"); fclose($f); But that is in the manuals too..... ? :'( :'( :'( Link to comment https://forums.phpfreaks.com/topic/195905-simple-auto-respond/#findComment-1029567 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.