Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.8.9

Bug #14780 Content-Type: Multipart/alternative is not set correctly.
Submitted: 2008-10-12 17:05 UTC
From: pf Assigned: alec
Status: Closed Package: Mail_Mime (version 1.5.2)
PHP Version: 5.2.6 OS: Windows XP
Roadmaps: 1.6.0RC1    

 [2008-10-12 17:05 UTC] pf (Poon Fung)
Description: ------------ If you call Mail_mime::headers() before Mail_mime::get(), no content type header is set. A work around for simple message is to include content-type in header list when calling Mail_mime::headers(). But for a multipart message, it is not possible to get message boundary to construct 'content-type: multipart/alternative; bournary="???"'. There is a simple solution that has not been document. First call Mail_mime::get() to get message body. This call also update message headers. Then call Mail_mime::headers() to get headers.


 [2008-10-15 07:16 UTC] doconnor (Daniel O'Connor)
Hey Poon, Want to turn that into a small exectuable test case that better demonstrates the problem? That way I can triage this as either a doc bug or a code bug.
 [2008-10-18 01:26 UTC] pf (Poon Fung)
Here is an example that does not work. $mime = new Mail_mime(); $headerList = array( 'To' => $toAddr, 'From' => $fromAddr, 'Subject' => $subject ); $headers = $mime->headers($headerList); $mime->setTXTBody($msgText); $mime->setHTMLBody($msgHtml); $body = $mime->get(); $paramList = array( 'host' => $host, 'port' => $port, 'auth' => $authenticate, 'username' => $user, 'password' => $password, 'localhost' => $host ); $obj =& Mail::factory('smtp', $paramList); $result = $obj->send($toAddr, $headers, $body); Instead of showing either HTML or text version of the email, the following is shown in the mail body. If you check the mail header you will not find "Content-Type" header. --=_4f74f92f9762bb05265ea88555a1dff3 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="ISO-8859-1" This is text message body --=_4f74f92f9762bb05265ea88555a1dff3 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="ISO-8859-1" <html> <body> This is HTML message body. </body> </html> --=_4f74f92f9762bb05265ea88555a1dff3-- ============================================= Here is an example that works correctly. Either text or HTML part is shown and mail header contains "Content-Type" such as: Content-Type: multipart/alternative; boundary="--=_4f74f92f9762bb05265ea88555a1dff3--" $mime = new Mail_mime(); $headerList = array( 'To' => $toAddr, 'From' => $fromAddr, 'Subject' => $subject ); $mime->setTXTBody($msgText); $mime->setHTMLBody($msgHtml); $body = $mime->get(); $headers = $mime->headers($headerList); $paramList = array( 'host' => $host, 'port' => $port, 'auth' => $authenticate, 'username' => $user, 'password' => $password, 'localhost' => $host ); $obj =& Mail::factory('smtp', $paramList); $result = $obj->send($toAddr, $headers, $body); IMPORTANT: Notice the order of the following two lines in the above examples. $body = $mime->get(); $headers = $mime->headers($headerList);
 [2009-12-30 12:43 UTC] alec (Aleksander Machniak)
-Assigned To: +Assigned To: alec -Roadmap Versions: +Roadmap Versions: 1.6.0RC1
 [2010-01-01 14:11 UTC] alec (Aleksander Machniak)
-Status: Assigned +Status: Closed
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.