I've been tearing my hair out best part of the last day trying to get a PHP
mail script working properly with Hotmail.
The script sends out multipart text/html emails - something I've done before
succesfully with ASP (don't ask me how - black science), and for the most
part it works OK. For some reason though when I try to view one of the
emails it produces through Hotmail's web interface, the entire body of the
email is blank - nothing in there at all, and when I view source, it doesn't
even look like the contents are there in Hotmail's HTML.
The problem seems to be something to do with the headers - if I remove all
headers from the mail() call then I can see the body of the email (albeit
all as text, obviously). If I add any headers at all via PHP, the email
appears to be blank in Hotmail (seems like the headers still work though, as I'm
able to change the "From" field).
Anyone have any idea what could be happening? Below is approximately what
the email-generating bit of the code looks like. BTW, I tried using \r\n
rather than just \n as recommended in the PHP manual, but this just seems to
bugger up the email even further, pushing some of the headers into the body
of the email - at least it does when I run it on a Unix server (which is where this needs to live) - on my Windows machine \r\n makes no difference.
$mime_boundary = "xxMuLtIpArT_BoUnDaRyxx";
$headers =
"From: $EMAILsendFromName <$EMAILsendFromEmail>\r\n" .
"MIME-Version: 1.0\n" .
"Content-Type: multipart/alternative;\n boundary=$mime_boundary\n"
;
$message = "This is a multi-part message in MIME format." .
"\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=ISO-8859-1\n" .
"Content-Transfer-Encoding: 7bit\n" .
$EMAILtextEmailFile .
"\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=ISO-8859-1\n" .
"Content-Transfer-Encoding: 7bit\n" .
$EMAILhtmlEmailFile .
"\n\n\n" .
"--{$mime_boundary}\n"
;
mail ($EMAILrecipients, $EMAILsubject, $message, $headers);
Dan Sumption
http://www.sumption.org