note 73508 deleted from ref.mail by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 20:09:36 +0000 |
| Subject: | note 73508 deleted from ref.mail by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155345@lists.php.net to get a copy of this message | ||
Note Submitter: br at winf dot at
----
The example function by nielsvandenberge at hotmail dot com is nice, but some Mail Programs (e.g.
Outlook Express, etc) do have problems and do not display any text or html of the mailbody - only as
a separate attachment.
The main problem is that the multipart/alternative part is not bounded correctly (a problem that
Outlook and other newer mailers seem to ignore). To make the function compatible to older/standard
mail-programs simply add a second mime boundary, which marks the bounds of the alternative parts:
<?
$mime_boundary_2 = "1_".$mime_boundary;
$msg .= "Content-Type: multipart/alternative;
boundary=\"".$mime_boundary_2."\"".$eol;
# Text Version
$msg .= "--".$mime_boundary_2.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= strip_tags(str_replace("<br>", "\n", $body)).$eol.$eol;
# HTML Version
$msg .= "--".$mime_boundary_2.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$msg .= $body.$eol.$eol;
# New Subboundary Finished
$msg .= "--".$mime_boundary_2."--".$eol.$eol;
# Top-Boundary Finished
$msg .= "--".$mime_boundary."--".$eol.$eol;
?>
The above snippet also corrects the missing second eol after Content-Transfer-Encoding: 8bit.