By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,086 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,086 IT Pros & Developers. It's quick & easy.

Need an Email Form that automatically Emails the user a confirmation Email?

P: 48
I have a form on my site that sends the form information directly to an email of mine. What I am wondering is the script that I would need to send a email back to the user who filled out my form, that would state something along the lines of "your Email was received. We will get back to you as soon as possible. I know this can be done, I have seen many sites that do it. I really like and I want to have it on my form. If you guys could please help me out or even link to an appropriate link that would tell me how to do this I would really appreciate it. Thank you guys.
Jan 9 '11 #1

✓ answered by AutumnsDecay

Have it send two emails.

If your form sends an email using PHP's mail() function, just add a second mail line directly after the the mail that gets sent to you.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. mail($to, $subject, $message, $headers);
  4. mail($to_user, $subject_user, $message_user, $headers_user);
  5.  
  6. ?>
  7.  
Now obviously you'd need to define the variables, but it should be pretty straight forward. Just use the information the user input as their email address for the second email's '$to_user' email address.

The rest you can just make yourself:

Expand|Select|Wrap|Line Numbers
  1. $subject_user = "Thanks for your email!";
  2. $message_user = "We have received your email. Thank you.";
  3.  
etc..

Share this Question
Share on Google+
21 Replies


AutumnsDecay
100+
P: 170
Have it send two emails.

If your form sends an email using PHP's mail() function, just add a second mail line directly after the the mail that gets sent to you.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. mail($to, $subject, $message, $headers);
  4. mail($to_user, $subject_user, $message_user, $headers_user);
  5.  
  6. ?>
  7.  
Now obviously you'd need to define the variables, but it should be pretty straight forward. Just use the information the user input as their email address for the second email's '$to_user' email address.

The rest you can just make yourself:

Expand|Select|Wrap|Line Numbers
  1. $subject_user = "Thanks for your email!";
  2. $message_user = "We have received your email. Thank you.";
  3.  
etc..
Jan 11 '11 #2

P: 48
Thank you Sir.
Jan 11 '11 #3

P: 48
Do i need it the " in-between the variable names.

mail($to_vis, $subject_user, $message_user,);

this is what I have, $vis is my customers name
Jan 11 '11 #4

P: 48
it gives me an error message
Jan 11 '11 #5

P: 48
Or perhaps I need it to read

mail($vis_user, $subject_user, $message_user,);

$subject_user = "Thanks for your email!";
$message_user = "We have received your email. We will be contacting you soon.";
Jan 11 '11 #6

P: 48
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled</title>
  6.  
  7. <style type="text/css">
  8. .centereddiv
  9.    {
  10.     width:400px;
  11.     height:200px;
  12.     position: absolute;
  13.     top:186px;
  14.     left:446px;
  15.        }
  16.    body {
  17.     background-image: url(http://www.penciledmemories.com/plainbg.jpg);
  18.     background-position:top center;
  19.     background-attachment:scroll;
  20.     background-repeat: no-repeat;
  21.     background-color: #150a04;
  22. }
  23. .style1 {color: #FFFFFF}
  24. body,td,th {
  25.     color: #FFFFFF;
  26. }
  27. </style>
  28.  
  29. </head>
  30. <body>
  31. <table width="100%" border="0" cellspacing="0" cellpadding="0" style="height:100%;">
  32.   <tr>
  33.     <td>&nbsp;</td>
  34.     <td width="734" valign="top">
  35.         <table width="734" border="0" cellspacing="0" cellpadding="0">
  36.           <tr>
  37.             <td valign="top" id="header">&nbsp;</td>
  38.           </tr>
  39.           <tr>
  40.             <td valign="top">
  41.                 <table width="734" border="0" cellspacing="0" cellpadding="0">
  42.                   <tr>
  43.                     <td valign="top" width="18">&nbsp;</td>
  44.                     <td valign="top" width="463" class="wel">
  45.                         <table width="463" border="0" cellspacing="0" cellpadding="0">
  46.                           <tr>
  47.                             <td valign="top" width="24"></td>
  48.                             <td valign="top" width="419">
  49.                                 <table width="419" border="0" cellspacing="0" cellpadding="0">
  50.                                   <tr><td height="12"></td></tr>
  51.                                   <tr>
  52.                                     <td valign="top"><div align="center"></div></td>
  53.                                   </tr>
  54.                                   <tr>
  55.                                     <td valign="top" height="20"></td>
  56.                                   </tr>
  57.                                   <tr>
  58.                                     <td valign="top">
  59.                                         <table width="419" border="0" cellspacing="0" cellpadding="0">
  60.                                           <tr>
  61.                                             <td valign="top"><div align="center"></p>
  62.                                             </div>
  63.                                               <h1 align="center" class="style4">&nbsp;</h1>
  64.                                               <h1 align="center" class="style4">&nbsp;</h1>
  65.                                               <h1 align="center" class="style4">
  66.                                                 <?php
  67.  
  68. $ip = $_POST['ip']; 
  69. $httpref = $_POST['httpref']; 
  70. $httpagent = $_POST['httpagent']; 
  71. $vis = $_POST['vis'];
  72. $vt = $_POST['vt'];
  73. $va = $_POST['va'];
  74. $vcsz = $_POST['vcsz'];
  75. $ve = $_POST['ve']; 
  76. $sd = $_POST['sd'];
  77. $ps = $_POST['ps'];
  78.  
  79.  
  80.  
  81. if (eregi('http:', $notes)) {
  82. die ("Do NOT try that! ! ");
  83. }
  84. if(!$ve == "" && (!strstr($ve,"@") || !strstr($ve,"."))) 
  85. {
  86. echo "<h2>Use Back - Enter valid e-mail</h2>\n"; 
  87. $badinput = "<h2>Feedback was NOT submitted</h2>\n";
  88. echo $badinput;
  89. die ("Go back! ! ");
  90. }
  91.  
  92. if(empty($vis) || empty($ve) || empty($ps )) {
  93. echo "<h2>Use Back - fill in all fields</h2>\n";
  94. die ("Use back! ! "); 
  95. }
  96.  
  97. $todayis = date("l, F j, Y, g:i a") ;
  98.  
  99. $attn = $attn ; 
  100. $subject = $attn; 
  101. $subject = "Website Customer";
  102.  
  103. $notes = stripcslashes($notes); 
  104.  
  105.  
  106. $message = " $todayis [EST] \n
  107. From: $vis ($ve)\n
  108. Address: $va \n
  109. City,State,Zip: $vcsz \n
  110. Telephone Number: $vt \n
  111. Portrait Size: $ps \n
  112. Special Directions: $sd \n 
  113.  
  114.  
  115. ";
  116.  
  117. $from = "From: $ve\r\n";
  118.  
  119.  
  120. mail("brandon@dedikateddesign.com", $subject, $message, $from);
  121. mail("brandonwatkins6082@yahoo.com", $subject, $message, $from);
  122. mail("sean@dedikateddesign.com", $subject, $message, $from);
  123.  
  124.  
  125.  
  126.  
  127. $subject_user = "Thanks for your email!";
  128. $message_user = "We have received your email. We will be contacting you soon.";
  129. mail($vis, $subject_user, $message_user,);
  130.  
  131.  
  132.  
  133. ?>
  134.  
  135.                                               </h1>
  136.                                               <h1 align="center" class="style4">Thank You!</h1>
  137.                                               <h1 align="center" class="style4">We will be contacting you soon.</h1>
  138. <p align="center">
  139. <span class="style4">Date: <?php echo $todayis ?></span><br />
  140. <span class="style4">Thank You :</span> <span class="style4"><?php echo $vis ?> (<?php echo $ve ?>) 
  141. </span><br />
  142.  
  143. <span class="style4"><strong>Portrait Size:</strong></span><?php echo $ps ?>
  144. <br /> 
  145. <span class="style4"><strong>Special Directions:</strong>
  146. <?php $notesout = str_replace("\r", "<br/>", $sd); 
  147. echo $notesout; ?>
  148. <br />
  149. <br />
  150. <?php echo $ip ?> 
  151.  
  152. <br />
  153. </span><br />
  154. <a href="http://www.penciledmemories.com" class="style3"> Home  </a> </td>
  155.                                             <td valign="top" width="21"></td>
  156.                                             <td valign="top" class="font1">&nbsp;</td>
  157.                                           </tr>
  158.                                     </table>                                    </td>
  159.                                   </tr>
  160.                                   <tr>
  161.                                     <td valign="top" height="37"></td>
  162.                                   </tr>
  163.                                   <tr>
  164.                                     <td valign="top">
  165.                                         <table width="419" border="0" cellspacing="0" cellpadding="0">
  166.                                           <tr>
  167.                                             <td valign="top" width="198">
  168.                                                 <table width="198" border="0" cellspacing="0" cellpadding="0">
  169.                                                   <tr>
  170.                                                     <td valign="top">&nbsp;</td>
  171.                                                   </tr>
  172.                                                   <tr>
  173.                                                     <td valign="top" height="17"></td>
  174.                                                   </tr>
  175.                                                   <tr>
  176.                                                     <td valign="top" style="padding-left:5px;">&nbsp;</td>
  177.                                                   </tr>
  178.                                                   <tr>
  179.                                                     <td valign="top" height="24"></td>
  180.                                                   </tr>
  181.                                                   <tr>
  182.                                                     <td valign="top" align="center">&nbsp;</td>
  183.                                                   </tr>
  184.                                                   <tr><td height="20"></td></tr>
  185.                                               </table>                                            </td>
  186.                                             <td valign="top" width="23"></td>
  187.                                             <td valign="top" width="198">
  188.                                                 <table width="198" border="0" cellspacing="0" cellpadding="0">
  189.                                                   <tr>
  190.                                                     <td valign="top">&nbsp;</td>
  191.                                                   </tr>
  192.                                                   <tr>
  193.                                                     <td valign="top" height="19"></td>
  194.                                                   </tr>
  195.                                                   <tr>
  196.                                                     <td valign="top" class="font1" style="padding-left:2px;">&nbsp;</td>
  197.                                                   </tr>
  198.                                                   <tr>
  199.                                                     <td valign="top" height="16"></td>
  200.                                                   </tr>
  201.                                                   <tr>
  202.                                                     <td valign="top">&nbsp;</td>
  203.                                                   </tr>
  204.                                                   <tr>
  205.                                                     <td valign="top" height="8"></td>
  206.                                                   </tr>
  207.                                                   <tr>
  208.                                                     <td valign="top">&nbsp;</td>
  209.                                                   </tr>
  210.                                               </table>                                            </td>
  211.                                           </tr>
  212.                                       </table>                                    </td>
  213.                                   </tr>
  214.                               </table>                            </td>
  215.                             <td valign="top" width="20"></td>
  216.                           </tr>
  217.                       </table>                    </td>
  218.                     <td valign="top" width="7">&nbsp;</td>
  219.                   <td valign="top" width="224">
  220.                         <table width="224" border="0" cellspacing="0" cellpadding="0">
  221.                           <tr>
  222.                             <td valign="top" class="login">
  223.                                 <table width="224" border="0" cellspacing="0" cellpadding="0">
  224.                                   <tr>
  225.                                     <td valign="top" width="18"></td>
  226.                                     <td valign="top" width="184">
  227.                                         <form action="" method="post" name="form1">
  228.                                             <table width="184" border="0" cellspacing="0" cellpadding="0">
  229.                                               <tr>
  230.                                                 <td valign="top" height="8"></td>
  231.                                               </tr>
  232.                                               <tr>
  233.                                                 <td valign="middle">
  234.                                                     <table width="184" border="0" cellspacing="0" cellpadding="0">
  235.                                                       <tr>
  236.                                                         <td valign="middle" align="right" class="font2">&nbsp;</td>
  237.                                                         <td valign="top">&nbsp;</td>
  238.                                                       </tr>
  239.                                                       <tr>
  240.                                                         <td valign="middle" align="right" class="font2">&nbsp;</td>
  241.                                                         <td valign="middle" align="right" class="font2"><div align="center"></div></td>
  242.                                                       </tr>
  243.                                                       <tr>
  244.                                                         <td valign="middle" align="right" width="53" class="font2"><div align="center"></div></td>
  245.                                                         <td valign="top" width="127"><div align="center">
  246.                                                           <p>&nbsp;</p>
  247.                                                           </div></td>
  248.                                                       </tr>
  249.                                                   </table>                                                </td>
  250.                                               </tr>
  251.                                               <tr>
  252.                                                 <td valign="top" height="11"></td>
  253.                                               </tr>
  254.                                               <tr>
  255.                                                 <td valign="top">&nbsp;</td>
  256.                                               </tr>
  257.                                               <tr>
  258.                                                 <td valign="top" height="9"></td>
  259.                                               </tr>
  260.                                               <tr>
  261.                                                 <td valign="top">
  262.                                                     <table width="184" border="0" cellspacing="0" cellpadding="0">
  263.                                                       <tr>
  264.                                                         <td valign="middle" width="127" class="font2">&nbsp;</td>
  265.                                                         <td valign="top" align="right" width="56">&nbsp;</td>
  266.                                                       </tr>
  267.                                                   </table>                                                </td>
  268.                                               </tr>
  269.                                           </table>
  270.                                         </form>                                    </td>
  271.                                     <td valign="top" width="22"></td>
  272.                                   </tr>
  273.                               </table>                            </td>
  274.                           </tr>
  275.                           <tr>
  276.                             <td valign="top" class="news">
  277.                                 <table width="224" border="0" cellspacing="0" cellpadding="0">
  278.                                   <tr>
  279.                                     <td valign="top" width="18"></td>
  280.                                     <td valign="top" width="184">
  281.                                         <table width="184" border="0" cellspacing="0" cellpadding="0">
  282.                                           <tr>
  283.                                             <td valign="top" height="43"></td>
  284.                                           </tr>
  285.                                           <tr>
  286.                                             <td valign="top">&nbsp;</td>
  287.                                           </tr>
  288.                                           <tr>
  289.                                             <td valign="top" height="31"></td>
  290.                                           </tr>
  291.                                           <tr>
  292.                                             <td valign="top">
  293.                                                 <table width="184" border="0" cellspacing="0" cellpadding="0">
  294.                                                   <tr>
  295.                                                     <td valign="top">&nbsp;</td>
  296.                                                     <td valign="top" width="17"></td>
  297.                                                     <td valign="top" width="104" class="font1">&nbsp;</td>
  298.                                                   </tr>
  299.                                               </table>                                            </td>
  300.                                           </tr>
  301.                                           <tr>
  302.                                             <td valign="top" height="31"></td>
  303.                                           </tr>
  304.                                           <tr>
  305.                                             <td valign="top">
  306.                                                 <table width="184" border="0" cellspacing="0" cellpadding="0">
  307.                                                   <tr>
  308.                                                     <td valign="top">&nbsp;</td>
  309.                                                     <td valign="top" width="17"></td>
  310.                                                     <td valign="top" width="104" class="font1">&nbsp;</td>
  311.                                                   </tr>
  312.                                               </table>                                            </td>
  313.                                           </tr>
  314.                                       </table>                                    </td>
  315.                                     <td valign="top" width="22"></td>
  316.                                   </tr>
  317.                               </table>                            </td>
  318.                           </tr>
  319.                       </table>                    </td>
  320.                     <td valign="top" width="22"></td>
  321.                   </tr>
  322.               </table>
  323.             </td>
  324.           </tr>
  325.           <tr>
  326.             <td valign="top" class="footer">
  327.                 <table width="734" border="0" cellspacing="0" cellpadding="0">
  328.                   <tr><td height="26"></td></tr>
  329.                   <tr>
  330.                     <td valign="top" width="18"></td>
  331.                     <td valign="top" width="500" class="font2"><img alt=""  src="file:///D|/Customer Websites/Contact Forms/images/spacer.gif" height="6" style="display:block "></td>
  332.                     <td valign="top" width="175" align="right" class="font4">&nbsp;</td>
  333.                     <td width="42"></td>
  334.                   </tr>
  335.               </table>
  336.             </td>
  337.           </tr>
  338.           <tr><td height="10"></td></tr>
  339.       </table>
  340.     </td>
  341.     <td>&nbsp;</td>
  342.   </tr>
  343. </table>
  344. <p style="text-align:center;font-family:Tahoma;font-size:12px;"><a href="http://www.dedikateddesign.com" style="font-size:12px;font-weight:bold;" title="Web Hosting">Web Hosting</a> by DediKated Design</p>
  345. </body>
  346. </html>
Jan 11 '11 #7

JKing
Expert 100+
P: 1,206
You've left out the fourth parameter in the mail() function which is the From header.
Jan 11 '11 #8

P: 48
Parse error: syntax error, unexpected ')' in /home/bw6082/public_html/sendeail.php on line 129
Jan 11 '11 #9

P: 48
Ok, the form didn't give me any errors when adding the headers mail function. But for some reason, when testing it, I didn't get the email from the form. Why could this be?
Jan 11 '11 #10

P: 48
Expand|Select|Wrap|Line Numbers
  1. $subject_user = "Thanks for your email!";
  2. $message_user = "We have received your email. We will be contacting you soon.";
  3. mail($vis, $subject_user, $message_user, $headers_user);
Jan 11 '11 #11

JKing
Expert 100+
P: 1,206
Did you check your junk mail?
Jan 11 '11 #12

P: 48
Ok great, It worked. JKing is there a way to send it and not make it go to the junk folder? Or does that automatically do that depending on the users email application? Also it is saying its coming from a weird email address. Is there a way to assign a certain email address in the form, so the users will see its from that specific email? Example: Sean@mysite.com
Jan 11 '11 #13

AutumnsDecay
100+
P: 170
$headers isn't 100% required. It's useful for sorting filters and for reply-to email addresses, but it will still send without any headers.

But, you are right. If I'm going to give an answer I should probably give the 100% answer.
Jan 11 '11 #14

P: 48
Autumns you were right Sir, I just didn't add it. It was my fault, not yours. But now I have another issue, can you direct it so it doesn't go to spam? OR is that impossible? Also it's saying its not coming from the right email address in the users :from, on their email address. It gives a weird address. Can you edit that, so you can state what email it is coming from?
Jan 11 '11 #15

AutumnsDecay
100+
P: 170
Sean, the best way to have it sort accurately for YOU is to have the 'from' part of the header point to a fake email address on your server.

For the end-user, you'll want to look into PHP Reply-To and From headers.

I don't mind helping, but you still need to do some of the leg work. :)
Jan 11 '11 #16

AutumnsDecay
100+
P: 170
Here's how my typical $headers variable looks:

Expand|Select|Wrap|Line Numbers
  1. $headers = 
  2.     'From: ' . $name . '<' . $email . '>' .  "\r\n" .
  3.     'Reply-To: ' . $email . "\r\n" .
  4.     'X-Mailer: PHP/' . phpversion();
  5.  
Jan 11 '11 #17

JKing
Expert 100+
P: 1,206
Read this link: PHP Mail()

Headers is technically an optional parameter. However you must always send a "From Header" which can either be set in the php.ini file or through the headers parameter.

Personally I prefer to set it in the headers parameter because I don't like messing around with my ini file.

Expand|Select|Wrap|Line Numbers
  1. $headers = "From: <youremail@yourdomain.com>";
  2.  
If it is currently showing up with a weird address you may want to look at what is stored in your $headers_user variable.
Jan 11 '11 #18

P: 48
I do apologize for asking so many questions. I do really appreciate the help. I just want to make sure I am doing this correctly. So I can save it for a template. Here is what I did, and this time I get no email, but I did assign the variables and the names. Usually this would work, I just can't grip what is wrong this time. Here is my code.

Expand|Select|Wrap|Line Numbers
  1. $from = "From: $ve\r\n";
  2.  
  3.  
  4. mail("brandon@dedikateddesign.com", $subject, $message, $from);
  5. mail("brandonwatkins6082@yahoo.com", $subject, $message, $from);
  6. mail("sean@dedikateddesign.com", $subject, $message, $from);
  7.  
  8.  
  9.  
  10. $headers = 
  11. 'From: ' . $name . '<' . $email . '>' .  "\r\n" .
  12. 'Reply-To: ' . $email . "\r\n" .
  13. 'X-Mailer: PHP/' . phpversion();
  14.  
  15. $name= "Penciled Memories";
  16. $email= "orders@penciledmemories.com";
  17. $subject_user = "Thank you.";
  18. $message_user = "We have received your email. We will be contacting you soon.";
  19. mail($ve_user, $subject_user, $message_user, $headers_user);
  20.  
  21.  
  22.  
  23. ?>
Jan 11 '11 #19

AutumnsDecay
100+
P: 170
Expand|Select|Wrap|Line Numbers
  1.  
  2. $name = "Penciled Memories";
  3. $email = "orders@penciledmemories.com";
  4. $subject_user = "Thank you.";
  5. $message_user = "We have received your email. We will be contacting you soon.";
  6.  
  7. $headers = 
  8. 'From: ' . $name . '<' . $email . '>' .  "\r\n" .
  9. 'Reply-To: ' . $email . "\r\n" .
  10. 'X-Mailer: PHP/' . phpversion();
  11.  
  12. mail($ve_user, $subject_user, $message_user, $headers);
  13.  
  14.  
That will work, though I'm not sure where you're setting $ve_user.

Just FYI, I was using _user at the end of everything as an example. It has no special effect on a variable.

Also, PHP is 100% linear, meaning the script is read from line 1 to line 100 in succession. Calling a variable on line 1 and setting it on line two will NOT work. A variable must be set before it can be used.

This is bad:
Expand|Select|Wrap|Line Numbers
  1. echo $name;
  2. $name = "Mat";
  3.  
This is good:
Expand|Select|Wrap|Line Numbers
  1. $name = "Mat";
  2. echo $name;
  3.  
Jan 11 '11 #20

P: 48
Expand|Select|Wrap|Line Numbers
  1. $headers = 
  2. 'From: ' . $name . '<' . $email . '>' .  "\r\n" .
  3. 'Reply-To: ' . $ve . "\r\n" .
  4. 'X-Mailer: PHP/' . phpversion();
  5. echo $name;
  6. echo $email;
  7.  
where would I assign these variables in the code above?

Expand|Select|Wrap|Line Numbers
  1. $subject_user = "Thank you.";
  2. $message_user = "We have received your email. We will be contacting you soon.";
Confused on this part.
Jan 11 '11 #21

P: 48
I figured it out guys. thank you for all the help.
Jan 12 '11 #22

Post your reply

Sign in to post your reply or Sign up for a free account.