homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Email formatting

 2:10 pm on Jul 18, 2011 (gmt 0)

I have an email I'm sending out via PHP and it looks good in Outlook, but if it goes to a godaddy web based email client it shows all of the HTML formatting and does not show who its from (it shows these in Outlook). Other HTML emails show fine in the web based email client.

Any thoughts? Here is the code:

//build and send the email
$to = $email;
$subject = 'Confirm your subscription';
$message =( "<html>\r\n");
$message .=( "<head>\r\n");
$message .=( "<title>Confirm</title>\r\n");
$message .=( "</head>\r\n");
$message .=( "<body>\r\n");
$message .=( "<h2>Thank You for registering!</h2>\r\n");
$message .=( "<p>To complete your registration, please click the link below.</p>\r\n");
$message .=(" <p><a href=\"http://www.site.com/confirmation.php?confirm=$visitor_hash\">Click here to confirm your interest.</a></p>\r\n");
$message .=( "<p>Welcome! We're glad you're here!</p>\r\n");
$message .=( "</body>\r\n");
$message .=( "</html>\r\n");

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: John Doe <info@site.com>\r\n";
mail($to, $subject, $message, $headers);

(I am going out of the country for a bit over a week, but will check and reply when I get back. Thanks!)



 2:36 pm on Jul 18, 2011 (gmt 0)

Does the "godaddy web based email client" support HTML emails? For any email client that doesn't (and for general reliability of sending emails, to not trip spam filters etc.) you should also include a plain text section.

Each line in the message body would normally be separated by LF "\n" rather than CRLF "\r\n". Whether this is critical I'm not sure. Headers, however, should be separated with CRLF "\r\n" (as you are doing).

Not the cause of your problem, but why are you enclosing your $message concatenating statements in (...) ?


 2:37 pm on Jul 18, 2011 (gmt 0)

Try including a plain text part in addition to the HTML.

This is a requirement per the email RFC's


 3:17 pm on Jul 18, 2011 (gmt 0)

Play around with the headers and the newlines. Mail is finicky that way and what works on one server doesn't on another. What this is telling you is that, for whatever reason, it's not recognizing the HTML header and is defaulting to plain text for the entire email. It may even be the order in which you output the headers . . . though it shouldn't matter.

Sometimes \r\n works, sometimes you need \n\n, and I've had some where neither work and I use a plain block for the entire header. Two examples,

$headers = "From: $from_email\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers = "From: $from_email
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1

In addition make sure your HTML email is a full HTML document, with <html><head><title>.... meta elements are not needed.


 4:06 pm on Jul 18, 2011 (gmt 0)

$headers = "From: $from_email  
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1

But this will just use whatever line endings are saved in the document. If switching between Windows / Linux / Mac then this has potential for disaster I would have said.

As rocknbil mentions, I too have found the order of the headers mattered. Notably "MIME-Version: 1.0". In fact, I found that if this wasn't the very last header then the Outlook Web Client refused to render HTML emails, instead displaying them as plain text.


 5:15 pm on Jul 18, 2011 (gmt 0)

Thanks guys, will try these when I get back! BTW, most of that code campe from the PHP mail function page. :-P


 3:53 pm on Jul 19, 2011 (gmt 0)

The rule is, "you use what works." :-)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved