note 57009 added to ref.mail
| From: | fontajos at phpeppershop dot com | Date: | Wed, 21 Sep 2005 15:24:10 +0000 |
| Subject: | note 57009 added to ref.mail | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95537@lists.php.net to get a copy of this message | ||
Problems with Microsoft Exchange and PHP as ISAPI-module
We found out, that if you want to send multipart mime emails using the PHP mail-function on a
Windows box using a Microsoft Exchange server, you have to use separate containers for the mail body
and the mail header.
In many examples like in http://www.zend.com/zend/trick/html-email.php
or in the book PHP developers cookbook you find html multipart/alternative mailing solutions that
build the mime header and the mail body into one PHP variable and send this as fourth argument
(header) to the PHP mail-function. This works fine on most systems but not on the above mentioned
combination.
We found a rather trivial solution: Simply split the mime mail header and the mail body into two
separate variables and give them separately to the PHP mail function, example:
<?php
//add From: header
$headers = "From: webserver@localhost\r\n";
//specify MIME version 1.0
$headers .= "MIME-Version: 1.0\r\n";
//unique boundary
$boundary = uniqid("HTMLDEMO");
//tell e-mail client this e-mail contains//alternate versions
$headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
//plain text version of message
$body = "--$boundary\r\n" .
"Content-Type: text/plain; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode("This is the plain text version!"));
//HTML version of message
$body .= "--$boundary\r\n" .
"Content-Type: text/html; charset=ISO-8859-1\r\n" .
"Content-Transfer-Encoding: base64\r\n\r\n";
$body .= chunk_split(base64_encode("This the <b>HTML</b> version!"));
//send message
mail("root@localhost", "An HTML Message", $body, $headers);
?>
----
Manual Page -- http://www.php.net/manual/en/ref.mail.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57009
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57009&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57009&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57009&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57009&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57009&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57009&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57009&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57009&report=yes
Search -- http://master.php.net/manage/user-notes.php