Exclamation marks appearing in HTML email

If you’re getting random exclamation marks appearing in the source of HTML emails being sent using PHP’s built in mail() function, then your HTML may be exceeding the maximum line length (998) specified in RFC 2822 Internet Message Format.

I found the easiest way to deal with it is to use the PHP function wordwrap(), eg.

$someHtml = wordwrap($someHtml, 996);
mail("[email protected]", "My subject", $someHtml, "MIME-Version: 1.0;\nContent-type: text/html; charset=iso-8859-1;\nFrom: [email protected]\n");

I discovered this while I was tidying up some of the email templates for a web application at my work.  There’s a long list of defects perpetrated by previous contributors, and I was tearing my hair out trying to work out why the content of a random table cell refused to center.  So now I have a greater appreciation for HTML email template designers, or maybe I just feel sorry for them…

This post is tagged: , ,

2 Responses to “Exclamation marks appearing in HTML email”
  1. 11.19.2008

    Great post. You are a real php junky. Will says the more exclamations marks the better!!!

  2. Thanks Philberino, I just seem to find solutions to things via random blog posts made by fellow developers. Thought I should try to return the favour… Though so far nobody has benefited from this, probably because 1000 other geeks have already posted their solutions!

      Leave a Reply

      Where’s Willie?


      As of Saturday 21st of August, 2011

      Tweets


      • No Tweets Available