PHP HTML emails and Outlook

After some considerable mucking about, I've cracked a particularly annoying and not much documented issue with sending HTML e-mails (in my case via PHP, but applies to any sendmail system) to Outlook Express / Windows Mail boxes.

It's all to do with the headers - and specifically what characters you use to escape them.
ALL lines should end with a \r\n escape sequence EXCEPT the MIME-Version: 1.0 which should be ONLY \n. Got it? This PHP works (certainly from a *nix server):

ini_set("sendmail_from", $fromAddr);
$headers="";
$headers.="From: ".$fromAddr."\r\n";
$headers.="Reply-To: ".$fromAddr."\r\n";
$headers .="Cc: ".$ccAddr."\r\n";
$headers.="MIME-Version: 1.0\n"; /* v.important NOT to put \r\n at the end as Outlook ends up escaping the WHOLE header */
$headers.="Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers.="Content-Transfer-Encoding: 8bit;\r\n";
mail( $toAddr, $subj, $body, $headers );

BONZA!

Comments

Popular posts from this blog

Installing LAMP Apache/MySQL/PHP on Chromebook/Chromebox

Installing Ubuntu Linux on your ChromeBox/ChromeBook

Changing your Mac OSX Terminal's default text editor