casmoedesigns Posted June 13, 2008 Share Posted June 13, 2008 Ok..... I'm stuck on something here. I have a form for a client of mine and he wants the form to be able to grab the email the users input into the form, and then be able to send an auto response to that email inputted. I've figured out how to make it work, but I just cant get the php code to grab the email put in by the user. This is what I have: <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'First Saturdays Guestlist'; // Your email address. This is where the form information will be sent. $emailadd = '[email protected]'; // Where to redirect after form is processed. $url = 'http://www.google.com'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // Email address put into Email Field<br /> $email_field = "Email"; <--------(If I put my email address here it works, so I just need the code that goes here to grab the email the users put in on the form) // --------------------------Do not edit below this line-------------------------- $auto_respond_subject = 'Thank you for contacting us!'; $auto_respond_body = "Thank you getting in touch with us!\nWe aim to respond to all enquiries within 24hours etc etc \n = line break"; mail($email_field, $auto_respond_subject, $auto_respond_body); $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: '.$emailadd.''); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/ Share on other sites More sharing options...
tapos Posted June 13, 2008 Share Posted June 13, 2008 please put your code in code tag Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-564715 Share on other sites More sharing options...
jesushax Posted June 13, 2008 Share Posted June 13, 2008 wheres your form code? use $email_field = $_POST["NameOfEmailField"]; Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-564718 Share on other sites More sharing options...
casmoedesigns Posted June 13, 2008 Author Share Posted June 13, 2008 Sorry about that..... Here is my form code: <CODE> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style1 {font-family: Calibri} --> </style> </head> <body> <form id="form1" name="form1" method="post" action="http://www.thefirstsaturdays.com/CasimerTestWork.php"> <table width="25%" border="0"> <tr> <td width="31%"><div align="right"><span class="style1">Name:</span></div></td> <td width="69%"><label> <input name="Name" type="text" class="style1" id="Name" size="30" /> </label></td> </tr> <tr> <td><div align="right"><span class="style1">Email:</span></div></td> <td><label> <input name="Email" type="text" class="style1" id="Email" size="30" /> </label></td> </tr> <tr> <td> </td> <td><div align="right"> <label> <input name="Submit2" type="reset" class="style1" value="Reset" /> <input name="Submit" type="submit" class="style1" value="Submit" /> </label> </div></td> </tr> </table> </form> </body> </html> </CODE> Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-564725 Share on other sites More sharing options...
jesushax Posted June 13, 2008 Share Posted June 13, 2008 so change $email_field = "Email"; to $email_field = $_POST["Email"]; and you done Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-564729 Share on other sites More sharing options...
casmoedesigns Posted June 13, 2008 Author Share Posted June 13, 2008 so change $email_field = "Email"; to $email_field = $_POST["Email"]; and you done Thank you, that worked! Now my problem is when the person receives an email back from us, the address says "[email protected]". Is there any way to change that to say "[email protected]"? Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-564744 Share on other sites More sharing options...
jesushax Posted June 13, 2008 Share Posted June 13, 2008 change mail($emailadd, $subject, $text, 'From: '.$emailadd.''); to mail($emailadd, $subject, $text, 'From: [email protected]'); Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-564752 Share on other sites More sharing options...
casmoedesigns Posted June 13, 2008 Author Share Posted June 13, 2008 change mail($emailadd, $subject, $text, 'From: '.$emailadd.''); to mail($emailadd, $subject, $text, 'From: [email protected]'); Its still coming back as "Nobody" Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-564764 Share on other sites More sharing options...
jonsjava Posted June 13, 2008 Share Posted June 13, 2008 wrong use of variables in your mail form: (and I organized the code some) <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'First Saturdays Guestlist'; // Your email address. This is where the form information will be sent. $emailadd = '[email protected]'; // Where to redirect after form is processed. $url = 'http://www.google.com'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // Email address put into Email Field $email_field = $_POST["Email"]; //<--------(If I put my email address here it works, so I just need the code that goes here to grab the email the users put in on the form) // --------------------------Do not edit below this line-------------------------- $auto_respond_subject = 'Thank you for contacting us!'; $auto_respond_body = "Thank you getting in touch with us!\nWe aim to respond to all enquiries within 24hours etc etc \n = line break"; mail($email_field, $auto_respond_subject, $auto_respond_body); $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') { echo "$key is empty"; die; } } $j = strlen($key); if ($j >= 20) { echo "Name of form element $key cannot be longer than 20 characters"; die; } $j = 20 - $j; for ($i = 1; $i <= $j; $i++) { $space .= ' '; } $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($email_field, $subject, $text, "From: $emailadd"); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-564772 Share on other sites More sharing options...
casmoedesigns Posted June 13, 2008 Author Share Posted June 13, 2008 Everything is working, I am just getting the wrong "sender" in the inbox once it replies to the user who imputed the email address. Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-564860 Share on other sites More sharing options...
casmoedesigns Posted June 14, 2008 Author Share Posted June 14, 2008 I was thinking, maybe you guys werent understanding what I was looking for. I am asking how do I change the email address that the user will see. In other words, if my buddy went to the form, typed in his name and email address, the autoresponder would hit my server then bounce something back to his email box. What I need to change is the email address that appears in his email box. Right now it is saying "[email protected]". That is wrong! The subject field is right but not the email that is bouncing back. Can you guys please help. Thanks!!!! Here is my PhP Code: <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'First Saturdays Guestlist'; // Your email address. This is where the form information will be sent. $emailadd = '[email protected]'; // Where to redirect after form is processed. $url = 'http://www.google.com'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // Email address put into Email Field<br /> $email_field = $_POST["Email"]; // --------------------------Do not edit below this line--------------------------<br /> $auto_respond_subject = 'First Saturdays Guest List!'; $auto_respond_body = "Thank you! Your request to be on the Guest List has been recieved."; mail($email_field, $auto_respond_subject, $auto_respond_body); $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: [email protected]'); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-565495 Share on other sites More sharing options...
casmoedesigns Posted June 14, 2008 Author Share Posted June 14, 2008 Hey guys, I've finally figured it out myself. lol All I had to do was add this: $headers = "From: [email protected]\r\nReply-To: [email protected]"; mail($email_field, $auto_respond_subject, $auto_respond_body, $headers); So the complete code, with everything working correctly is: <?php //--------------------------Set these paramaters-------------------------- // Subject of email sent to you. $subject = 'First Saturdays Guestlist'; // Your email address. This is where the form information will be sent. $emailadd = '[email protected]'; // Where to redirect after form is processed. $url = 'http://www.thefirstsaturdays.com'; // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty. $req = '0'; // Email address put into Email Field. $email_field = $_POST["Email"]; // --------------------------Do not edit below this line--------------------------<br /> $auto_respond_subject = 'First Saturdays Guest List!'; $auto_respond_body = "Thank you! Your request to be on the Guest List has been received."; $headers = "From: [email protected]\r\nReply-To: [email protected]"; mail($email_field, $auto_respond_subject, $auto_respond_body, $headers); $text = "Results from form:\n\n"; $space = ' '; $line = ' '; foreach ($_POST as $key => $value) { if ($req == '1') { if ($value == '') {echo "$key is empty";die;} } $j = strlen($key); if ($j >= 20) {echo "Name of form element $key cannot be longer than 20 characters";die;} $j = 20 - $j; for ($i = 1; $i <= $j; $i++) {$space .= ' ';} $value = str_replace('\n', "$line", $value); $conc = "{$key}:$space{$value}$line"; $text .= $conc; $space = ' '; } mail($emailadd, $subject, $text, 'From: [email protected]'); echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">'; ?> Hopefully this thread will help others.............. Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-565534 Share on other sites More sharing options...
eng/nehal Posted June 29, 2008 Share Posted June 29, 2008 could you pleeeeeeeease tell me where should i put this php code exactly in my site to have an auto responder,thanks in advance,but please hurry up as i need it badly:) Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-577158 Share on other sites More sharing options...
casmoedesigns Posted July 2, 2008 Author Share Posted July 2, 2008 If you have a form on your website, just put the location of the php file on your server in the form tag. OR if you're using Dreamweaver, locate the form tag, click in it, and on the bottom you should see a box called "Action", Put the php file location in that box. It will transmit any information that is in the form. Just be sure to change the emails because I dont want to be getting any from your website. lol could you pleeeeeeeease tell me where should i put this php code exactly in my site to have an auto responder,thanks in advance,but please hurry up as i need it badly:) Link to comment https://forums.phpfreaks.com/topic/110054-php-form-autoresponder/#findComment-580016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.