I got this sucker working for Form Tools last month after working my butt off making sense of the many idiosyncracies of the many servers out there. Well, turns out I missed a problem. After half a dozen people complained I bumped this up on my priorities and investigated it.
If you need to ever send HTML+text emails in PHP, I'd thoroughly recommend the following article: http://www.zend.com/zend/trick/html-email.php
But be careful not to deviate from the example code without fully understanding it! Every last aspect of the code is there for a purpose, including the occasional double endlines. Unfortunately, the writer doesn't delve into the details in any great depth so one is apt to assume they're not important. One thing that's not covered is determining an endline based on OS type. Here's my tweaked version:
PHP:
// determine the end of line character (based on OS) $eol = "\n"; $eol = "\r\n"; $eol = "\r"; // add From: header $headers = "From: webserver@localhost$eol"; //specify MIME version 1.0 $headers .= "MIME-Version: 1.0$eol"; // unique boundary // tell e-mail client this e-mail contains alternate versions $headers .= "Content-Type: multipart/alternative" . "; boundary = $boundary$eol$eol"; // message to people with clients who don't understand MIME $headers .= "This is a MIME encoded message.$eol"; // plain text version of message $headers .= "--$boundary$eol" . "Content-Type: text/plain; charset=ISO-8859-1$eol" . "Content-Transfer-Encoding: base64$eol$eol"; // HTML version of message $headers .= "--$boundary\r\n" . "Content-Type: text/html; charset=ISO-8859-1$eol" . "Content-Transfer-Encoding: base64$eol$eol"; // send message
I can vouch for the code working on Windows and Unix servers. Good luck...!









No comments yet.
RSS feed for comments on this post. TrackBack URI