469,282 Members | 2,123 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

How to reply with html email using php form

RJOent
3
I am adding a contact form on my website, and I would like to send an autoreply email in html. I can send one with php in simple text, but no clue how to add html. Please help!

Here is my code so I can get their info:

Expand|Select|Wrap|Line Numbers
  1.     $FirstName = $_REQUEST['firstname'] ;
  2.     $lastname = $_REQUEST['lastname'] ;
  3.     $companyname = $_REQUEST['companyname'] ;
  4.     $title = $_REQUEST['title'] ;
  5.     $phone = $_REQUEST['phone'] ;
  6.     $phoneext = $_REQUEST['phoneext'] ;
  7.     $fax = $_REQUEST['fax'] ;
  8.     $email = $_REQUEST['email'] ;
  9.     $inquiry = $_REQUEST['inquiry'] ;
  10.     $subject = "Inquiry Request submitted";
  11.     $EmailBody = "This in an inquiry e-mail sent from Website\r\nInquiry Request has been submitted by $FirstName $lastname\n";
  12.     $EmailDetails = "Company Name: $companyname\n";
  13.     $EmailDetails = $EmailDetails."Title: " . $title  . "\n"  ;
  14.     $EmailDetails = $EmailDetails."Phone: " . $phone . "\n";
  15.     $EmailDetails = $EmailDetails."Phone Ext: " .  $phoneext . "\n";
  16.     $EmailDetails = $EmailDetails."Fax: ".$fax."\n"  ;
  17.     $EmailDetails = $EmailDetails."Email: " .$email . "\n";
  18.     $EmailDetails = $EmailDetails."Inquiry:\r\n ".  $inquiry  . "\n";
  19.     $message = "$EmailBody \n $EmailDetails";
  20.   mail( "rjo@mydomain.com", $subject, $message, "From: $FirstName $lastname <$email>" );
  21.   header( "Location: http://www.mydomain.com/thankyou.php" );
  22.  

And then here is the auto-reply:

Expand|Select|Wrap|Line Numbers
  1.   $email = $HTTP_POST_VARS[email];
  2.   $mailto = "$email";
  3.   $mailsubj = "Thank you for your interest in LSO, Inc.";
  4.   $mailhead = 'From: No Reply <noreply@lso-inc.com>' . "\r\n";
  5.   reset ($HTTP_POST_VARS);
  6.   $mailbody = "Dear $FirstName $lastname,\r\nThank you for your interest.   We will be sure to get back to you within 24 hours.\r\nFor a quicker response, please call us at 1 (800) MY-DOMAIN. \r\n \r\nHere is your original request:\r\n \r\n";
  7.   while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
  8.   if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
  9.  
Where and how to include the html email I designed baffles me. Any help would be appreciated.
May 10 '10 #1
4 4399
dlite922
1,584 Expert 1GB
@RJOent
As always, the PHP manual is a great place to start: php.net/mail. Don't worry, I sometimes forget to search the manual before asking here too.

Look in the fourth example, pay attention to this code

Expand|Select|Wrap|Line Numbers
  1.  
  2. // To send HTML mail, the Content-type header must be set
  3. $headers  = 'MIME-Version: 1.0' . "\r\n";
  4. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  5.  
  6.  
Let me know if that helps,





Dan
May 10 '10 #2
RJOent
3
@dlite922

I had tried the information on that page before and it didn't work. I took a look at it this morning realized what I was doing wrong and voila!

Thanks Dan!
May 11 '10 #3
dlite922
1,584 Expert 1GB
Can you share with us what you did so that others in your situation can benefit?

Thanks,



Dan
May 11 '10 #4
RJOent
3
@dlite922
Hello Dave,

Sorry it took me a little while to come back and reply. I think I have the code to where I want it. And I would love to share it with others.


Here is how I retrieve my values from the contact form:
Expand|Select|Wrap|Line Numbers
  1. $FirstName = $_REQUEST['firstname'] ;
  2. $lastname = $_REQUEST['lastname'] ;
  3. $companyname = $_REQUEST['companyname'] ;
  4. $title = $_REQUEST['title'] ;
  5. $phone = $_REQUEST['phone'] ;
  6. $phoneext = $_REQUEST['phoneext'] ;
  7. $fax = $_REQUEST['fax'] ;
  8. $email = $_REQUEST['email'] ;
  9. $inquiry = $_REQUEST['inquiry'] ;
  10.  


And I forward the info to our sales team:

Expand|Select|Wrap|Line Numbers
  1. # -=-=-=- MIME BOUNDARY
  2. $mime_boundary = "----LSO Inc----".md5(time());
  3. # -=-=-=- MAIL HEADERS
  4. $to  = 'person1i@rjoentertainment.com' . ', '; // note the comma
  5. $to .= 'person2@rjoentertainment.com' . ', '; // note the comma
  6. $to .= 'person3@rjoentertainment.com' . ', '; // note the comma
  7. $to .= 'person4@rjoentertainment.com';
  8.  
  9. $subject = "Inquiry Request submitted";
  10. $headers = "From: $firstname $lastname <$email>\n";
  11. $headers .= "Reply-To: My Company <info@mydomain.com>\n";
  12. //$headers .= "BCC: ";
  13. $headers .= "MIME-Version: 1.0\n";
  14. $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
  15.  
  16. $message .= "--$mime_boundary\n";
  17. $message .= "Content-Type: text/html; charset=UTF-8\n";
  18. $message .= "Content-Transfer-Encoding: 8bit\n\n";
  19.  
  20. $message .= "<html>\n";
  21. $message .= "<body bgcolor=\"#FFFFFF\">\n";
  22. $message .= "<table width=\"500\" height=\"159\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >";
  23. $message .="<tr>";
  24. $message .="<td height=\"110\" colspan=\"4\" bgcolor=\"#052c48\"><font face=\"Arial\" color=\"#ffffff\"><center><b>New Inquiry Request";
  25. $message .="<br>from<br>Lorem Ipsum</b></center></font></td>";
  26. $message .="</tr>";
  27. $message .="<tr>";
  28. $message .="<td height=\"50\" colspan=\"4\" bgcolor=\"ffffff\"><font face=\"Arial\" color=\"#000000\">The following inquiry has bee submitted via the Lorem Ipsum website:</font></td>";
  29. $message .="</tr>";
  30. $message .="<tr>";
  31. $message .="<td width=\"1%\"></td>";
  32. $message .="<td colspan=\"3\">&nbsp;</td>";
  33. $message .="</tr>";
  34. $message .="<tr>";
  35. $message .="<td>&nbsp;</td>";
  36. $message .="<td width=\"25%\"><b><font face=\"Arial\" color=\"#000000\">Name:</b></font></td>";
  37. $message .="<td align=\"left\" ><font face=\"Arial\" color=\"#000000\">:</font></td>";
  38. $message .="<td><font face=\"Arial\" color=\"#000000\">$FirstName $lastname</font></td>";
  39. $message .="<tr>";
  40. $message .="<td>&nbsp;</td>";
  41. $message .="<td><b><font face=\"Arial\" color=\"#000000\">Title</b></font></td>";
  42. $message .="<td>:</td>";
  43. $message .="<td><font face=\"Arial\" color=\"#000000\">$title</font></td>";
  44. $message .="</tr>";
  45. $message .="</tr>";
  46. $message .="<tr>";
  47. $message .="<td>&nbsp;</td>";
  48. $message .="<td><b><font face=\"Arial\" color=\"#000000\">Company Name</b></font></td>";
  49. $message .="<td>:</td>";
  50. $message .="<td><font face=\"Arial\" color=\"#000000\">$companyname</font></td>";
  51. $message .="</tr>";
  52. $message .="<tr>";
  53. $message .="<td>&nbsp;</td>";
  54. $message .="<td><b><font face=\"Arial\" color=\"#000000\">E-mail</font></b></td>";
  55. $message .="<td>:</td>";
  56. $message .="<td><font face=\"Arial\" color=\"#000000\">$email</font></td>";
  57. $message .="</tr>";
  58. $message .="<tr>";
  59. $message .="<td>&nbsp;</td>";
  60. $message .="<td><b><font face=\"Arial\" color=\"#000000\">Telephone</font></b></td>";
  61. $message .="<td>:</td>";
  62. $message .="<td><font face=\"Arial\" color=\"#000000\">$phone</font></td>";
  63. $message .="</tr>";
  64. $message .="<tr>";
  65. $message .="<td>&nbsp;</td>";
  66. $message .="<td><b><font face=\"Arial\" color=\"#000000\">Ext</b></font></td>";
  67. $message .="<td>:</td>";
  68. $message .="<td><font face=\"Arial\" color=\"#000000\">$phoneext</font></td>";
  69. $message .="</tr>";
  70. $message .="<tr>";
  71. $message .="<td>&nbsp;</td>";
  72. $message .="<td><b><font face=\"Arial\" color=\"#000000\">Fax</b></font></td>";
  73. $message .="<td>:</td>";
  74. $message .="<td><font face=\"Arial\" color=\"#000000\">$fax</font></td>";
  75. $message .="</tr>";
  76. $message .="<tr>";
  77. $message .="<td>&nbsp;</td>";
  78. $message .="<td><b><font face=\"Arial\" color=\"#000000\">Comments</b></font></td>";
  79. $message .="<td>:</td>";
  80. $message .="<td><font face=\"Arial\" color=\"#000000\">$inquiry</font></td>";
  81. $message .="</tr>";
  82. $message .="<tr>";
  83. $message .="<td padding=\"10\" height=\"100\" colspan=\"4\" bgcolor=\"#c0d8f1\"><font face=\"Arial\" color=\"#000000\" size=\"2\"><center>An automated response email has already been sent to the customer advising them that they will be contacted in one (1) business day.</font></center></td>";
  84. $message .="</tr>";
  85. $message .="</table>";
  86. $message .= "</body>\n";
  87. $message .= "</html>\n";
  88. # -=-=-=- FINAL BOUNDARY
  89. $message .= "--$mime_boundary--\n\n";
  90. # -=-=-=- SEND MAIL
  91. $mail_sent = @mail( $to, $subject, $message, $headers );
  92. //echo $mail_sent ? "Mail sent" : "Mail failed";
  93. if($mail_sent)
  94. {
  95. header('Location: http://www.rjoentratinemnt.com/thanks.html');
  96. }
  97. else
  98. {
  99. header('Location:http://www.rjoentratinemnt.com/fail.html');
  100. }
  101.  

Then I send an auto-reply to the customer:

Expand|Select|Wrap|Line Numbers
  1. $companyname = "MyCompany";
  2. $companymail = "noreply@mydomain.com";
  3. $bcc = "me_thedesigner@mydomain.com";
  4.  
  5. # -=-=-=- MIME BOUNDARY
  6. $mime_boundary = "----rjoentertainment.com----".md5(time());
  7. # -=-=-=- MAIL HEADERS
  8. $mailhead = "From: $companyname <$companymail>\n";
  9. $mailhead .= "BCC: RJOent <$bcc>\n";
  10. $mailhead .= "MIME-Version: 1.0\n";
  11. $mailhead .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
  12.  
  13. $mailto = "$email";
  14.  
  15. $mailbody = "--$mime_boundary\n";
  16. $mailbody .= "Content-Type: text/html; charset=UTF-8\n";
  17. $mailbody .= "Content-Transfer-Encoding: 8bit\n\n";
  18.  
  19. $mailbody .= "<html>";
  20. $mailbody .= "<body leftmargin=\"0\" marginwidth=\"0\" topmargin=\"0\" marginheight=\"0\" offset=\"0\" bgcolor=\"#052c48\" >";
  21. $mailbody .= "<table width=\"100%\" cellpadding=\"10\" cellspacing=\"0\" bgcolor=\"#052c48\" >";
  22. $mailbody .= "<tr>";
  23. $mailbody .= "<td valign=\"top\" align=\"center\">";
  24.  
  25. $mailbody .= "<table width=\"600\" cellpadding=\"0\" cellspacing=\"0\">";
  26. $mailbody .= "<tr>";
  27. $mailbody .= "<td style=\"background-color:#d6ebff;border-top:0px solid #000000;border-bottom:1px solid #FFFFFF;text-align:center;\" align=\"center\"><span style=\"font-size:10px;color:#996600;line-height:200%;font-family:verdana;text-decoration:none;\">Email not displaying correctly? <a href=\"http://www.rjoentertainment.com.com\" style=\"font-size:10px;color:#996600;line-height:200%;font-family:verdana;text-decoration:none;\">View it in your browser.</a></span></td>";
  28.  
  29. $mailbody .= "</tr>";
  30.  
  31. $mailbody .= "<tr>";
  32. $mailbody .= "<td align=\"left\" valign=\"middle\" style=\"background-color:#FFFFFF;border-top:0px solid #333333;border-bottom:10px solid #FFFFFF;\"><center><a href=\"\"><IMG id=editableImg1 SRC=\"http://www.rjoentertainment.com.com/images/email/email_top_mpt.jpg\" BORDER=\"0\" width=\"600\" height=\"110\" title=\"LSO, Inc.\"  alt=\"title1.\" align=\"center\"></a></center></td>";
  33. $mailbody .= "</tr>";
  34.  
  35.  
  36. $mailbody .= "</table>";
  37.  
  38. $mailbody .= "<table width=\"600\" cellpadding=\"20\" cellspacing=\"0\" bgcolor=\"#FFFFFF\">";
  39. $mailbody .= "<tr>";
  40.  
  41. $mailbody .= "<td bgcolor=\"#FFFFFF\" valign=\"top\" width=\"400\" ALIGN=\"justify\" style=\"font-size:12px;color:#000000;line-height:150%;font-family:trebuchet ms;\">";
  42.  
  43. $mailbody .= "<p>";
  44. $mailbody .= "<span style=\"font-size:20px;font-weight:bold;color:#052c48;font-family:arial;line-height:110%;\">Dear $FirstName $lastname,</span><br>";
  45.  
  46. $mailbody .= "Thank you for contacting RJOentertainment.com.  We have received your request for information regarding our Package Testing / Validation services and we will respond within one (1) business day.";
  47. $mailbody .= "<br><br>";
  48. $mailbody .= "</p>";
  49. $mailbody .= "<p>";
  50. $mailbody .= "<span style=\"font-size:20px;font-weight:bold;color:#052c48;font-family:arial;line-height:110%;\">For a quicker response</span><br>";
  51. $mailbody .= "please call us at (714) 555-1234 and ask for one of the representatives listed to the right of this message.</p> ";
  52. $mailbody .= "<br>Thanks again for your inquiry,<br><br>";
  53. $mailbody .= "<b>RJO<br>";
  54. $mailbody .= "<b><i><font face=\"times new roman\">A division of</font></i><br>";
  55. $mailbody .= "<b><i><font face=\"times new roman\" color=\"#0d2d84\">Life Science Outsourcing, Inc.</font></i></b>";
  56. $mailbody .= "<br><br>";
  57. //$mailbody .= "<b>rjoentertainment.com, Inc.</b><br>";
  58. //$mailbody .= "1234 Main Street<br>";
  59. //$mailbody .= "Townville, Ca 90000<br>";
  60. //$mailbody .= "Tel ( 714) 555-1234<br>";
  61. //$mailbody .= "Fax (714) 555-1235 <br>";
  62.  
  63. $mailbody .= "</p>";
  64.  
  65. $mailbody .= "</td>";
  66.  
  67.  
  68. $mailbody .= "<td width=\"200\" valign=\"top\" style=\"background-color:#FFFFFF;border-left:1px dashed #CCCCCC;text-align:left;\">";
  69. $mailbody .= "<span style=\"font-size:11px;font-weight:normal;color:#303d4a;font-family:arial;line-height:150%;\">";
  70.  
  71. $mailbody .= "<span style=\"font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;\">Person 1</span><br>";
  72. $mailbody .= "Business Development Manager<br>";
  73. $mailbody .= "<a href=\"mailto:email@rjoentertainment.com?subject=RE: Medical Package Testing\">email@rjoentertainment.com</a><br>";
  74. $mailbody .= "(714) 555-1234<br>";
  75. $mailbody .= "<a href=\"http://www.linkedin.com/in/rjosunai\"><img border=\"0\" src=\"http://static01.linkedin.com/img/logos/logo_82x23.png\" BORDER=\"0\" width=\"83\" height=\"23\" title=\"LinkedIn\"  alt=\"LinkedIn\" align=\"center\"></a>";
  76.  
  77. $mailbody .= "<br><br><br><br><br><br>";
  78.  
  79. $mailbody .= "<span style=\"font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;\">Person 2</span><br>";
  80. $mailbody .= "Business Development Manager<br>";
  81. $mailbody .= "<a href=\"mailto:email@rjoentertainment.com?subject=RE: Medical Package Testing\">email@rjoentertainment.com</a><br>";
  82. $mailbody .= "(714) 555-1234<br>";
  83. $mailbody .= "<a href=\"http://www.linkedin.com/in/rjosunai\"><img border=\"0\" src=\"http://static01.linkedin.com/img/logos/logo_82x23.png\" BORDER=\"0\" width=\"83\" height=\"23\" title=\"LinkedIn\"  alt=\"LinkedIn\" align=\"center\"></a>";
  84.  
  85.  
  86. $mailbody .= "<br><br><br><br><br><br>";
  87.  
  88. $mailbody .= "<span style=\"font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;\">Person 3</span><br>";
  89. $mailbody .= "Business Development Manager<br>";
  90. $mailbody .= "<a href=\"mailto:email@rjoentertainment.com?subject=RE: Medical Package Testing\">email@rjoentertainment.com</a><br>";
  91. $mailbody .= "(714) 555-1234<br>";
  92. $mailbody .= "<a href=\"http://www.linkedin.com/in/rjosunai\"><img border=\"0\" src=\"http://static01.linkedin.com/img/logos/logo_82x23.png\" BORDER=\"0\" width=\"83\" height=\"23\" title=\"LinkedIn\"  alt=\"LinkedIn\" align=\"center\"></a>";
  93. $mailbody .= "</span>";
  94. $mailbody .= "</td>";
  95. $mailbody .= "</tr>";
  96. $mailbody .= "<tr>";
  97. $mailbody .= "<td style=\"background-color:#FFFFCC;border-top:10px solid #FFFFFF;\" valign=\"top\" colspan=\"2\">";
  98. $mailbody .= "<span style=\"font-size:10px;color:#996600;line-height:100%;font-family:verdana;\">";
  99. $mailbody .= "You are receiving this email because you indicated an interest in My Company. If you no";
  100. $mailbody .= "longer wish to receive our emails, just send a quick note to us at unsubscribe@mydomain.com with";
  101. $mailbody .= "UNSUBSCRIBE in the Subject line. <br />";
  102. $mailbody .= "<br />";
  103. $mailbody .= "</span>";
  104. $mailbody .= "</td>";
  105. $mailbody .= "</tr>";
  106. $mailbody .= "</table>";
  107. $mailbody .= "</td>";
  108. $mailbody .= "</tr>";
  109. $mailbody .= "</table>";
  110. $mailbody .= "</body>";
  111. $mailbody .= "</html>";
  112.  
  113. $mailsubj = "Thank you for your interest in Lorem Ipsum";
  114.  
  115.  
  116. mail($mailto, $mailsubj, $mailbody, $mailhead );
  117.  
I am still a newbie at php, so this might not be the best method. My goal, is to send our sales team the info provided in our info request form and the send the potential customer a nice looking email that basically says "Thanks, we'll be in touch soon."

So far this works. I hope someone benefits from this and if there is a better way, or you see an error in my code, please let me know!

Thanks Dave!
May 21 '10 #5

Post your reply

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

Similar topics

4 posts views Thread by philphanluvr | last post: by
4 posts views Thread by Ann | last post: by
2 posts views Thread by Brett | last post: by
reply views Thread by akylitis | last post: by
6 posts views Thread by patrice.fiset | last post: by
2 posts views Thread by bthubbard | last post: by
2 posts views Thread by lawpoop | last post: by
1 post views Thread by rahia307 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.