Exclamation marks appearing in HTML email

Posted by Streetdaddy™ on November 11th, 2008 filed in Geek

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(“someone@somewhere.com”, “My subject”, $someHtml, “MIME-Version: 1.0;\nContent-type: text/html; charset=iso-8859-1;\nFrom: someone@somewhere.com\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…


2 Responses to “Exclamation marks appearing in HTML email”

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

Philip spoke on

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!

Streetdaddyâ„¢ spoke on

Leave a Comment

FireStats icon Powered by FireStats