Hello,
I'm trying to send an HTML formatted email when a user submits a form on my website. I've tested the email with several webmail applications and also with Apple's Mail.app and it works perfectly. The only place I'm having trouble is with MS Outlook (both 2003 and 2007).

When the email is viewed in Outlook, I see the raw HTML code preceded with the following header info - "Content-type:text/html;charset=iso-8859-1".

I've searched online and on this board for common solutions and have tried them all, including:

- Remove the <html><head> and <title> tags. (I've tried this, but still no luck)
- Make sure that the HTML is W3C Validated. (I've succesfully validated it)
- Make sure that Outlook is set to view HTML content, and not convert to plain text. (I've made sure that my settings are correct).

I've even directly copied and pasted other people's code, that they claim is working for them, and I still have no luck in Outlook, so there must be something I'm missing here.

I'm pulling my hair out on this one! Can anyone please shed some light on this for me or find a problem in my code below?

Thanks!
Dave

<?php

// REQUEST CONTACT INFO
  $fname = $_REQUEST['fname'];
  $lname = $_REQUEST['lname'];
  $company = $_REQUEST['company'];
  $phone = $_REQUEST['phone'];
  $email = $_REQUEST['email'] ;
  $address1 = $_REQUEST['address1'];
  $address2 = $_REQUEST['address2'];
  $city = $_REQUEST['city'];
  $state = $_REQUEST['state'];
  $zip = $_REQUEST['zip'];

// REQUEST PHONE INFO
  $stock1 = $_REQUEST['phone1stock'];
  $barcode1 = $_REQUEST['phone1barcode']; 

// ASSEMBLE HEADERS
  $to = "email@mydomain.com";
  $subject = "Subject Here";
  $headers = "From: $email\r\n";
  $headers .= "Reply-To: $email\r\n";
  $headers .= "MIME-Version: 1.0" . "\r\n";
  $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

 // E-MAIL MESSAGE
  $message = "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\">
<head>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />
<title>Form Confirmation</title> 
</head> 
<body>
  <h2>Contact Information</h2>
<p>
<strong>Name:</strong> $fname $lname <br />
<strong>Company:</strong> $company <br />
<strong>Phone:</strong> $phone <br />
<strong>Email:</strong> $email <br />
<strong>Address 1:</strong> $address1 <br />
<strong>Address 2:</strong> $address2 <br />
<strong>City:</strong> $city <br />
<strong>State:</strong> $state <br />
<strong>Zip:</strong> $zip <br />
</p>
<h2>Phone Information</h2>
<h3 style=\"padding:0px; margin:10px 0px 4px 0px;\">Phone 1</h3>
<strong>Stock No:</strong> $stock1 <br />
<strong>Barcode No:</strong> $barcode1 <br />
</body>
</html>
";
?> 

    I'm sorry, I forgot to paste a piece of code in my last post.

    After the HTML Email Code, I have this:

    <?php
    
      // CONFIRMATION MESSAGE
    if ( mail($to,$subject,$message,$headers) ) {
       echo "Thank you, your information has been submitted.  You will be contacted shortly.";
       } else {
       echo "The email has failed! Please Resubmit your information. If this problem persists, please contact us at me@myemail.com ";
       }
    
    ?>
    

      for html email you do not need (and should remove) doctype declaration, fancy html type, meta tags and for that matter you can ditch head and title

      it should be html as it was 20 years ago

      e.g.:
      <html>
      <body> and then the text

      that may not fix your problem

        creatceous wrote:

        that may not fix your problem

        I think you meant it will not fix the problem (which appears to be that Outlook isn't correctly interpreting/parsing an e-mail header... a rather important one, considering the issue).

        @: Try adding a space after the colon in "Content-type:".

          Thanks for the quick replies...

          cretaceous - Thanks for your suggestion. I've tried removing the content you mentioned and literally broke the code down to something as simple as:
          <html><body>test</body></html> and I still get an unformatted email.

          bradgrafelman - I believe you're right, that outlook is not parsing the header. I made the change you recommended and I still get the unformatted email, preceded with "Content-type: text/html;charset=iso-8859-1".

          I've seen quite a few variations of how people type out Content-Type and MIME Version headers. For instance, some use \r\n while other use just an \n... some capitalize certain words while others do not... I've tried several of these different variations. Do you think the problem could something as simple as that?

            djs1 wrote:

            For instance, some use \r\n while other use just an \n... some capitalize certain words while others do not... I've tried several of these different variations. Do you think the problem could something as simple as that?

            The only reason to use a LF line ending (\n) instead of a CRLF (\r\n) is if your MTA is improperly converting the former into the latter (resulting in "\r\n" becoming "\r\r\n").

            As for the headers themselves, they are case-insensitive.

            Try two things: first, try adding another line ending (so another set of "\r\n") after the last header. If that doesn't work, try removing both sets so that there is no line ending after the last header.

            EDIT: Also, you can read about the line ending issue I was talking about above in the PHP manual page for [man]mail/man.

              THANK YOU!

              I visited the link you sent me, and found the answer there.

              For anyone else who may be reading this and experiencing the same problem - The solution I found was to change any instances of r\n to \n in the $headers. ( http://us2.php.net/manual/en/function.mail.php#74873 ). I've now tested it in several webmail apps, Apple Mail app, and Outlook 2003 & 2007 and the HTML is formatted properly.

              Thanks again! This one was killing me!
              Dave

                Write a Reply...