How to reply with html email using php form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RJOent
    New Member
    • May 2010
    • 3

    How to reply with html email using php form

    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:

    Code:
    	$FirstName = $_REQUEST['firstname'] ;
    	$lastname = $_REQUEST['lastname'] ;
    	$companyname = $_REQUEST['companyname'] ;
    	$title = $_REQUEST['title'] ;
    	$phone = $_REQUEST['phone'] ;
    	$phoneext = $_REQUEST['phoneext'] ;
    	$fax = $_REQUEST['fax'] ;
    	$email = $_REQUEST['email'] ;
    	$inquiry = $_REQUEST['inquiry'] ;
    	$subject = "Inquiry Request submitted";
    	$EmailBody = "This in an inquiry e-mail sent from Website\r\nInquiry Request has been submitted by $FirstName $lastname\n";
    	$EmailDetails = "Company Name: $companyname\n";
    	$EmailDetails = $EmailDetails."Title: " . $title  . "\n"  ;
    	$EmailDetails = $EmailDetails."Phone: " . $phone . "\n";
    	$EmailDetails = $EmailDetails."Phone Ext: " .  $phoneext . "\n";
    	$EmailDetails = $EmailDetails."Fax: ".$fax."\n"  ;
    	$EmailDetails = $EmailDetails."Email: " .$email . "\n";
    	$EmailDetails = $EmailDetails."Inquiry:\r\n ".  $inquiry  . "\n";
    	$message = "$EmailBody \n $EmailDetails";
      mail( "rjo@mydomain.com", $subject, $message, "From: $FirstName $lastname <$email>" );
      header( "Location: http://www.mydomain.com/thankyou.php" );

    And then here is the auto-reply:

    Code:
      $email = $HTTP_POST_VARS[email];
      $mailto = "$email";
      $mailsubj = "Thank you for your interest in LSO, Inc.";
      $mailhead = 'From: No Reply <noreply@lso-inc.com>' . "\r\n";
      reset ($HTTP_POST_VARS);
      $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";
      while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
      if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
    Where and how to include the html email I designed baffles me. Any help would be appreciated.
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Originally posted by RJOent
    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:

    Code:
    	$FirstName = $_REQUEST['firstname'] ;
    	$lastname = $_REQUEST['lastname'] ;
    	$companyname = $_REQUEST['companyname'] ;
    	$title = $_REQUEST['title'] ;
    	$phone = $_REQUEST['phone'] ;
    	$phoneext = $_REQUEST['phoneext'] ;
    	$fax = $_REQUEST['fax'] ;
    	$email = $_REQUEST['email'] ;
    	$inquiry = $_REQUEST['inquiry'] ;
    	$subject = "Inquiry Request submitted";
    	$EmailBody = "This in an inquiry e-mail sent from Website\r\nInquiry Request has been submitted by $FirstName $lastname\n";
    	$EmailDetails = "Company Name: $companyname\n";
    	$EmailDetails = $EmailDetails."Title: " . $title  . "\n"  ;
    	$EmailDetails = $EmailDetails."Phone: " . $phone . "\n";
    	$EmailDetails = $EmailDetails."Phone Ext: " .  $phoneext . "\n";
    	$EmailDetails = $EmailDetails."Fax: ".$fax."\n"  ;
    	$EmailDetails = $EmailDetails."Email: " .$email . "\n";
    	$EmailDetails = $EmailDetails."Inquiry:\r\n ".  $inquiry  . "\n";
    	$message = "$EmailBody \n $EmailDetails";
      mail( "rjo@mydomain.com", $subject, $message, "From: $FirstName $lastname <$email>" );
      header( "Location: http://www.mydomain.com/thankyou.php" );

    And then here is the auto-reply:

    Code:
      $email = $HTTP_POST_VARS[email];
      $mailto = "$email";
      $mailsubj = "Thank you for your interest in LSO, Inc.";
      $mailhead = 'From: No Reply <noreply@lso-inc.com>' . "\r\n";
      reset ($HTTP_POST_VARS);
      $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";
      while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
      if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
    Where and how to include the html email I designed baffles me. Any help would be appreciated.
    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

    Code:
    // To send HTML mail, the Content-type header must be set
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    Let me know if that helps,





    Dan

    Comment

    • RJOent
      New Member
      • May 2010
      • 3

      #3
      Originally posted by dlite922
      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

      Code:
      // To send HTML mail, the Content-type header must be set
      $headers  = 'MIME-Version: 1.0' . "\r\n";
      $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
      Let me know if that helps,





      Dan

      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!

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #4
        Can you share with us what you did so that others in your situation can benefit?

        Thanks,



        Dan

        Comment

        • RJOent
          New Member
          • May 2010
          • 3

          #5
          Originally posted by dlite922
          Can you share with us what you did so that others in your situation can benefit?

          Thanks,



          Dan
          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:
          Code:
          $FirstName = $_REQUEST['firstname'] ;
          $lastname = $_REQUEST['lastname'] ;
          $companyname = $_REQUEST['companyname'] ;
          $title = $_REQUEST['title'] ;
          $phone = $_REQUEST['phone'] ;
          $phoneext = $_REQUEST['phoneext'] ;
          $fax = $_REQUEST['fax'] ;
          $email = $_REQUEST['email'] ;
          $inquiry = $_REQUEST['inquiry'] ;


          And I forward the info to our sales team:

          Code:
          # -=-=-=- MIME BOUNDARY
          $mime_boundary = "----LSO Inc----".md5(time());
          # -=-=-=- MAIL HEADERS
          $to  = 'person1i@rjoentertainment.com' . ', '; // note the comma
          $to .= 'person2@rjoentertainment.com' . ', '; // note the comma
          $to .= 'person3@rjoentertainment.com' . ', '; // note the comma
          $to .= 'person4@rjoentertainment.com';
          
          $subject = "Inquiry Request submitted";
          $headers = "From: $firstname $lastname <$email>\n";
          $headers .= "Reply-To: My Company <info@mydomain.com>\n";
          //$headers .= "BCC: ";
          $headers .= "MIME-Version: 1.0\n";
          $headers .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
          
          $message .= "--$mime_boundary\n";
          $message .= "Content-Type: text/html; charset=UTF-8\n";
          $message .= "Content-Transfer-Encoding: 8bit\n\n";
          
          $message .= "<html>\n";
          $message .= "<body bgcolor=\"#FFFFFF\">\n";
          $message .= "<table width=\"500\" height=\"159\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >";
          $message .="<tr>";
          $message .="<td height=\"110\" colspan=\"4\" bgcolor=\"#052c48\"><font face=\"Arial\" color=\"#ffffff\"><center><b>New Inquiry Request";
          $message .="<br>from<br>Lorem Ipsum</b></center></font></td>";
          $message .="</tr>";
          $message .="<tr>";
          $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>";
          $message .="</tr>";
          $message .="<tr>";
          $message .="<td width=\"1%\"></td>";
          $message .="<td colspan=\"3\">&nbsp;</td>";
          $message .="</tr>";
          $message .="<tr>";
          $message .="<td>&nbsp;</td>";
          $message .="<td width=\"25%\"><b><font face=\"Arial\" color=\"#000000\">Name:</b></font></td>";
          $message .="<td align=\"left\" ><font face=\"Arial\" color=\"#000000\">:</font></td>";
          $message .="<td><font face=\"Arial\" color=\"#000000\">$FirstName $lastname</font></td>";
          $message .="<tr>";
          $message .="<td>&nbsp;</td>";
          $message .="<td><b><font face=\"Arial\" color=\"#000000\">Title</b></font></td>";
          $message .="<td>:</td>";
          $message .="<td><font face=\"Arial\" color=\"#000000\">$title</font></td>";
          $message .="</tr>";
          $message .="</tr>";
          $message .="<tr>";
          $message .="<td>&nbsp;</td>";
          $message .="<td><b><font face=\"Arial\" color=\"#000000\">Company Name</b></font></td>";
          $message .="<td>:</td>";
          $message .="<td><font face=\"Arial\" color=\"#000000\">$companyname</font></td>";
          $message .="</tr>";
          $message .="<tr>";
          $message .="<td>&nbsp;</td>";
          $message .="<td><b><font face=\"Arial\" color=\"#000000\">E-mail</font></b></td>";
          $message .="<td>:</td>";
          $message .="<td><font face=\"Arial\" color=\"#000000\">$email</font></td>";
          $message .="</tr>";
          $message .="<tr>";
          $message .="<td>&nbsp;</td>";
          $message .="<td><b><font face=\"Arial\" color=\"#000000\">Telephone</font></b></td>";
          $message .="<td>:</td>";
          $message .="<td><font face=\"Arial\" color=\"#000000\">$phone</font></td>";
          $message .="</tr>";
          $message .="<tr>";
          $message .="<td>&nbsp;</td>";
          $message .="<td><b><font face=\"Arial\" color=\"#000000\">Ext</b></font></td>";
          $message .="<td>:</td>";
          $message .="<td><font face=\"Arial\" color=\"#000000\">$phoneext</font></td>";
          $message .="</tr>";
          $message .="<tr>";
          $message .="<td>&nbsp;</td>";
          $message .="<td><b><font face=\"Arial\" color=\"#000000\">Fax</b></font></td>";
          $message .="<td>:</td>";
          $message .="<td><font face=\"Arial\" color=\"#000000\">$fax</font></td>";
          $message .="</tr>";
          $message .="<tr>";
          $message .="<td>&nbsp;</td>";
          $message .="<td><b><font face=\"Arial\" color=\"#000000\">Comments</b></font></td>";
          $message .="<td>:</td>";
          $message .="<td><font face=\"Arial\" color=\"#000000\">$inquiry</font></td>";
          $message .="</tr>";
          $message .="<tr>";
          $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>";
          $message .="</tr>";
          $message .="</table>";
          $message .= "</body>\n";
          $message .= "</html>\n";
          # -=-=-=- FINAL BOUNDARY
          $message .= "--$mime_boundary--\n\n";
          # -=-=-=- SEND MAIL
          $mail_sent = @mail( $to, $subject, $message, $headers );
          //echo $mail_sent ? "Mail sent" : "Mail failed";
          if($mail_sent)
          {
          header('Location: http://www.rjoentratinemnt.com/thanks.html');
          }
          else
          {
          header('Location:http://www.rjoentratinemnt.com/fail.html');
          }

          Then I send an auto-reply to the customer:

          Code:
          $companyname = "MyCompany";
          $companymail = "noreply@mydomain.com";
          $bcc = "me_thedesigner@mydomain.com";
          
          # -=-=-=- MIME BOUNDARY
          $mime_boundary = "----rjoentertainment.com----".md5(time());
          # -=-=-=- MAIL HEADERS
          $mailhead = "From: $companyname <$companymail>\n";
          $mailhead .= "BCC: RJOent <$bcc>\n";
          $mailhead .= "MIME-Version: 1.0\n";
          $mailhead .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary\"\n";
          
          $mailto = "$email";
          
          $mailbody = "--$mime_boundary\n";
          $mailbody .= "Content-Type: text/html; charset=UTF-8\n";
          $mailbody .= "Content-Transfer-Encoding: 8bit\n\n";
          
          $mailbody .= "<html>";
          $mailbody .= "<body leftmargin=\"0\" marginwidth=\"0\" topmargin=\"0\" marginheight=\"0\" offset=\"0\" bgcolor=\"#052c48\" >";
          $mailbody .= "<table width=\"100%\" cellpadding=\"10\" cellspacing=\"0\" bgcolor=\"#052c48\" >";
          $mailbody .= "<tr>";
          $mailbody .= "<td valign=\"top\" align=\"center\">";
          
          $mailbody .= "<table width=\"600\" cellpadding=\"0\" cellspacing=\"0\">";
          $mailbody .= "<tr>";
          $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>";
          
          $mailbody .= "</tr>";
          
          $mailbody .= "<tr>";
          $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>";
          $mailbody .= "</tr>";
          
          
          $mailbody .= "</table>";
          
          $mailbody .= "<table width=\"600\" cellpadding=\"20\" cellspacing=\"0\" bgcolor=\"#FFFFFF\">";
          $mailbody .= "<tr>";
          
          $mailbody .= "<td bgcolor=\"#FFFFFF\" valign=\"top\" width=\"400\" ALIGN=\"justify\" style=\"font-size:12px;color:#000000;line-height:150%;font-family:trebuchet ms;\">";
          
          $mailbody .= "<p>";
          $mailbody .= "<span style=\"font-size:20px;font-weight:bold;color:#052c48;font-family:arial;line-height:110%;\">Dear $FirstName $lastname,</span><br>";
          
          $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.";
          $mailbody .= "<br><br>";
          $mailbody .= "</p>";
          $mailbody .= "<p>";
          $mailbody .= "<span style=\"font-size:20px;font-weight:bold;color:#052c48;font-family:arial;line-height:110%;\">For a quicker response</span><br>";
          $mailbody .= "please call us at (714) 555-1234 and ask for one of the representatives listed to the right of this message.</p> ";
          $mailbody .= "<br>Thanks again for your inquiry,<br><br>";
          $mailbody .= "<b>RJO<br>";
          $mailbody .= "<b><i><font face=\"times new roman\">A division of</font></i><br>";
          $mailbody .= "<b><i><font face=\"times new roman\" color=\"#0d2d84\">Life Science Outsourcing, Inc.</font></i></b>";
          $mailbody .= "<br><br>";
          //$mailbody .= "<b>rjoentertainment.com, Inc.</b><br>";
          //$mailbody .= "1234 Main Street<br>";
          //$mailbody .= "Townville, Ca 90000<br>";
          //$mailbody .= "Tel ( 714) 555-1234<br>";
          //$mailbody .= "Fax (714) 555-1235 <br>";
          
          $mailbody .= "</p>";
          
          $mailbody .= "</td>";
          
          
          $mailbody .= "<td width=\"200\" valign=\"top\" style=\"background-color:#FFFFFF;border-left:1px dashed #CCCCCC;text-align:left;\">";
          $mailbody .= "<span style=\"font-size:11px;font-weight:normal;color:#303d4a;font-family:arial;line-height:150%;\">";
          
          $mailbody .= "<span style=\"font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;\">Person 1</span><br>";
          $mailbody .= "Business Development Manager<br>";
          $mailbody .= "<a href=\"mailto:email@rjoentertainment.com?subject=RE: Medical Package Testing\">email@rjoentertainment.com</a><br>";
          $mailbody .= "(714) 555-1234<br>";
          $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>";
          
          $mailbody .= "<br><br><br><br><br><br>";
          
          $mailbody .= "<span style=\"font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;\">Person 2</span><br>";
          $mailbody .= "Business Development Manager<br>";
          $mailbody .= "<a href=\"mailto:email@rjoentertainment.com?subject=RE: Medical Package Testing\">email@rjoentertainment.com</a><br>";
          $mailbody .= "(714) 555-1234<br>";
          $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>";
          
          
          $mailbody .= "<br><br><br><br><br><br>";
          
          $mailbody .= "<span style=\"font-size:15px;font-weight:bold;color:#333333;font-family:arial;line-height:150%;\">Person 3</span><br>";
          $mailbody .= "Business Development Manager<br>";
          $mailbody .= "<a href=\"mailto:email@rjoentertainment.com?subject=RE: Medical Package Testing\">email@rjoentertainment.com</a><br>";
          $mailbody .= "(714) 555-1234<br>";
          $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>";
          $mailbody .= "</span>";
          $mailbody .= "</td>";
          $mailbody .= "</tr>";
          $mailbody .= "<tr>";
          $mailbody .= "<td style=\"background-color:#FFFFCC;border-top:10px solid #FFFFFF;\" valign=\"top\" colspan=\"2\">";
          $mailbody .= "<span style=\"font-size:10px;color:#996600;line-height:100%;font-family:verdana;\">";
          $mailbody .= "You are receiving this email because you indicated an interest in My Company. If you no";
          $mailbody .= "longer wish to receive our emails, just send a quick note to us at unsubscribe@mydomain.com with";
          $mailbody .= "UNSUBSCRIBE in the Subject line. <br />";
          $mailbody .= "<br />";
          $mailbody .= "</span>";
          $mailbody .= "</td>";
          $mailbody .= "</tr>";
          $mailbody .= "</table>";
          $mailbody .= "</td>";
          $mailbody .= "</tr>";
          $mailbody .= "</table>";
          $mailbody .= "</body>";
          $mailbody .= "</html>";
          
          $mailsubj = "Thank you for your interest in Lorem Ipsum";
          
          
          mail($mailto, $mailsubj, $mailbody, $mailhead );
          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!

          Comment

          Working...