note 68880 deleted from ref.mail by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 20:13:02 +0000 |
| Subject: | note 68880 deleted from ref.mail by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155358@lists.php.net to get a copy of this message | ||
Note Submitter: Nick Baicoianu
----
In response to jcwebb's excellent post regarding multipart/alternative and attachments: the
code works great in sending attachments, but I got inconsistent results across different email
clients (MS Outlook worked, but Thunderbird and mutt didn't) when displaying the HTML/plain
text alternate portion.
To fix this, you need to define a new MIME boundary for the HTML/Plain text alternates section ONLY
- this way you can "nest" the two together so the alternate works properly in all email
clients.
here's a modified version of the code for the message body only (see jcwebb's post for the
entire message code)
<?
$msg = "";
# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: application/pdf; name=\"".$letter."\"".$eol;
// sometimes i have to send MS Word, use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment;
filename=\"".$letter."\"".$eol.$eol; // !! This line needs TWO end of lines
!! IMPORTANT !!
$msg .= $f_contents.$eol.$eol;
# Setup for text OR html -
$msg .= "--".$mime_boundary.$eol;
$htmlalt_mime_boundary = $mime_boundary."_htmlalt"; //we must define a different MIME
boundary for this section for the alternative to work properly in all email clients
$msg .= "Content-Type: multipart/alternative;
boundary=\"".$htmlalt_mime_boundary."\"".$eol;
# Text Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= "This is a multi-part message in MIME format.".$eol;
$msg .= "If you are reading this, please update your email-reading-software.".$eol;
$msg .= "+ + Text Only Email from Genius Jon + +".$eol.$eol;
# HTML Version
$msg .= "--".$htmlalt_mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
//close the html/plain text alternate portion
$msg .= "--".$htmlalt_mime_boundary."--".$eol.$eol;
# Finished
$msg .= "--".$mime_boundary."--".$eol.$eol;
?>