PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Mail » Mail_Mime » Bug #788

HTML & TEXT mail components not recognized in Apple's Mail program

Details

Submitted2004-02-18 21:13 UTC
Fromcryogen at mac dot com
Assignedsean
StatusClosed
PackageMail_Mime
PHP Version4.3.4
OSMac OSX 10.3.2
Roadmaps(Not assigned)

Comments

[2004-02-18 21:13 UTC] cryogen at mac dot com

Description:
------------
I am creating and sending both text and HTML versions of a short
welcome email to newly registered users. The emails come across fine
when I browse them in Microsoft Entourage (same as Outlook for
Windows). But when I view the same message in Apple's latest Mail
program, I see both the text and HTML versions in the same email in raw
unrendered (for the HTML) text: see below for copy of the email raw
code. I have pasted a portion of the code I am using to generate the
HTML version of the email below. Note the text version (stored in $text)
is exactly the same without the HTML tags.

Reproduce code:
---------------
// Build the HTML version of the email
$html = file_get_contents("contact_new_email.html");
$html = str_replace("{stylesheet}",$stylesheet_url,$html);
$html = str_replace("{con_f_name}",$qd['con_f_name'],$html);
$html = str_replace("{directory_name}",$qd['directory_name'],$html);
$html = str_replace("{p_word}",$qd['p_word'],$html);
$html = str_replace("{login_link}",$login_link_html,$html);

$crlf = "\r\n";

$hdrs = array("From"=>"name <{$Gdefault_email_from}>", "Subject"=>"Welcome and Thanks");

$mime = new Mail_mime($crlf);

$mime->setTXTBody($text);
$mime->setHTMLBody($html);

$body = $mime->get();
$hdrs = $mime->headers($hdrs);

$mail =& Mail::factory("mail");
$mail->send("{$qd['con_f_name']} {$qd['con_l_name']} <{$qd['con_email']}>", $hdrs, $body);

Expected result:
----------------
I expected to see only the HTML version for my HTML capable email
program. I receive many HTML-based emails a day and they have
always come through just fine.

Actual result:
--------------
In looking at the RAW email body from the failed email, I see the
following header for the text part:

--=_c5c318bf383d66ef921df4e521a35cfe
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit

and the following header in front of the second half of the email (html
section):

--=_c5c318bf383d66ef921df4e521a35cfe
Content-Type: text/html; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

I have noticed in the emails I receive successfully that I see the
following header at the top:

MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0012_B903734E.404771FE"

Followed by:

------=_NextPart_000_0012_B903734E.404771FE
Content-Type: text/plain
Content-Transfer-Encoding: 8bit

Followed by the HTML section:

------=_NextPart_000_0012_B903734E.404771FE
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

It seems like maybe the PEAR class should generate the multipart
header first so the email is recognized as a milti-part email.

[2004-02-18 21:15 UTC] cryogen at mac dot com

Correcting some bug information

[2004-02-25 18:22 UTC] gschlossnagle at php dot net

what is the result of this line:

$hdrs = $mime->headers($hdrs);

[2004-03-10 22:46 UTC] blake at mediafence dot com

I was just about to post a new bug on this. I have the same problem using Outlook 2002 as a reader.

I have fixed my version of Mail_Mime if anyone wants a patch. I just don't know how to get the patch to the right person.

Blake schwendiman

[2004-09-09 17:54 UTC] paul at silksystems dot com

Im also encountering this using outlook express 6

-however only from some php servers.

email is readable when generated on server A - email is not readable when generated on server B (both using same code)

there are minor diferences between the servers, but nothing that *should* affect this.

[2004-12-13 18:10 UTC] cryogen at mac dot com

Good points and sorry for the lack of details. I am
going to start fresh with another project that requires
PEAR MAIL classes, so will retire this bug in favor of a
fresh one (if I still have problems) when I begin
implementing the new system.

[2005-03-01 21:38 UTC] sales dot web at webmultimediadesigner dot com

Hi All,

I am facing the same problem with Outlook Express with the eclosed script. The script is working fine in any webmail like (Yahoo). But it's showing the HTML code in the Outlook 2002.

I have uploaded the same code to http://www.webmultimediadesigner.com/code.txt

Please help me what to do!

With Regards,

Nick
http://www.webmultimediadesigner.com/

--------------------------

<?php
# You can use this script to submit your forms or to receive orders by email.
$MailToAddress = "abc@yourdomain.com"; // your email address
$redirectURL = "http://www.webmultimediadesigner.com/"; // the URL of the thank you page.

# optional settings
$MailSubject = "Web Multimedia Designer"; // the subject of the email
$MailToCC = ""; // CC (carbon copy) also send the email to this address (leave empty if you don't use it)
# in the $MailToCC field you can have more then one e-mail address like "a@yoursite.com, b@yoursite.com, c@yoursite.com"

# If you are asking for a name and an email address in your form, you can name the input fields "name" and "email".
# If you do this, the message will apear to come from that email address and you can simply click the reply button to answer it.

# If you have a multiple selection box or multiple checkboxes, you MUST name the multiple list box or checkbox as "name[]" instead of just "name"
# you must also add "multiple" at the end of the tag like this: <select name="myselectname[]" multiple>
# you have to do the same with checkboxes

# This script was written by George A. & Calin S. from Web4Future.com
# There are no copyrights in the sent emails.

# SPAMASSASSIN RATING: 0.4

# DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING ===================================================
# ver. 1.6.2
if (preg_match ("/".$_SERVER["SERVER_NAME"]."/i", $_SERVER["HTTP_REFERER"])) {
$w4fMessage = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head><body>";
if (count($_GET) >0) {
reset($_GET);
while(list($key, $val) = each($_GET)) {
$GLOBALS[$key] = $val;
if (is_array($val)) {
$w4fMessage .= "<b>$key:</b> ";
foreach ($val as $vala) {
$vala =stripslashes($vala);
$w4fMessage .= "$vala, ";
}
$w4fMessage .= "<br>";
}
else {
$val = stripslashes($val);
if (($key == "Submit") || ($key == "submit")) { }
else { if ($val == "") { $w4fMessage .= "$key: - <br>"; }
else { $w4fMessage .= "<b>$key:</b> $val<br>"; }
}
}
} // end while
}//end if
else {
reset($_POST);
while(list($key, $val) = each($_POST)) {
$GLOBALS[$key] = $val;
if (is_array($val)) {
$w4fMessage .= "<b>$key:</b> ";
foreach ($val as $vala) {
$vala =stripslashes($vala);
$w4fMessage .= "$vala, ";
}
$w4fMessage .= "<br>";
}
else {
$val = stripslashes($val);
if (($key == "Submit") || ($key == "submit")) { }
else { if ($val == "") { $w4fMessage .= "$key: - <br>"; }
else { $w4fMessage .= "<b>$key:</b> $val<br>"; }
}
}
} // end while
}//end else
$w4fMessage = "<font face=verdana size=2>".$w4fMessage."</font></body></html>";
if (!$email) {$email = "server@site.com";}
if (!mail($MailToAddress, $MailSubject, $w4fMessage, "From: $name <$email>\r\nReply-To: $name <$email>\r\nMessage-ID: <". md5(rand()."".time()) ."@". ereg_replace("www.","",$_SERVER["SERVER_NAME"]) .">\r\nMIME-Version: 1.0\r\nX-Priority: 3\r\nX-Mailer: PHP/" . phpversion()."\r\nX-MimeOLE: Produced By Web4Future Easiest Form2Mail v1.5\r\nBCc: $MailToCC\r\nContent-Type: text/html; charset=ISO-8859-1\r\nContent-Transfer-Encoding: 8bit\r\n")) { echo "Error sending e-mail!";}
else { header("Location: ".$redirectURL); }
} else { echo "<center><font face=verdana size=3 color=red><b>ILLEGAL EXECUTION DETECTED!</b></font></center>";}
?>

[2005-09-07 15:39 UTC] ben at wieck dot com

I am also encountering this problem. I do no see that there was a fix for it.

I am using Mail_Mime 1.3.1 and Mail 1.1.8 with the following code:

$mime = new Mail_Mime();
$mime->setTxtBody($plain);
$mime->setHtmlBody($html);
$body = $mime->get();

$hdrs = $mime->headers($headers);
$mail = &Mail::factory('mail');
$mail->send($to, $hdrs, $body);

Running PHP 5.0.4 configured with:
Configure Command => './configure' '--prefix=/usr/include' '--with-config-file-path=/etc/php5' '--with-zlib-dir=/opt/local' '--with-jpeg-dir=/opt/local' '--with-tiff-dir=/opt/local' '--with-png-dir=/opt/local' '--with-gd' '--with-mysql=/usr/include/mysql' '--with-xml' '--with-libxml-dir=/opt/local' '--with-apxs' '--with-sqlite' '--disable-short-tags' '--with-openssl' '--with-openssl-dir=/opt/local/include/openssl' '--enable-calendar' '--enable-ftp' '--with-gettext=/opt/local' '--with-mcrypt=/opt/local' '--with-mhash=/opt/local' '--with-embedded-mysqli' '--enable-pcntl' '--enable-soap' '--enable-sockets' '--with-pear' '--enable-sigchild'

[2005-09-07 15:59 UTC] ben at wieck dot com

Solution! Apple's Mail appreciates "\n" as the line feed character. I was under the impression this was the default for Mail_Mime. After adding "\n" to Mail_Mime's constructor

- $mime = new Mail_Mime();
+ $mime = new Mail_Mime("\n");

Apple Mail worked!