问题描述
|
我正在使用最新版本的PEAR mail_mime模块,但遇到了一个奇怪的问题。将HTML图像附加到电子邮件时,文本部分会停止正常工作。我的“无法正常工作”是指如果我尝试在Thunderbird中以文本形式查看消息(或在PINE中查看消息),则不会显示我设置为“文本”的内容电子邮件的一部分;它试图以文本可读的方式解析HTML信息。 HTML部分中的所有内容均按预期工作。
这是我瘦下来的代码:
//Headers
$headers[\'From\'] = \"[email protected]\";
$headers[\'To\'] = \"[email protected]\";
$headers[\'Subject\'] = \"A MIME Email\";
//Text Portion
$text = \"This is the text portion.\";
//HTML Portion
$html = \"<html><body><p><img src=\'image.png\' />This is the HTML portion.</p></body></html>\";
//Set up the MIME email
$mime = new Mail_mime(array(\'eol\' => \"\\r\\n\"));
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addHTMLImage(\"/path/to/image.png\",\"image/png\");
//Prepare the message to be sent
$body = $mime->get();
$headers = $mime->headers($headers);
//Send the message via SMTP
$mail_obj =& Mail::factory(\'smtp\',array(\'host\' => \'smtp.server.com\',\'port\' => 25));
$mail_obj->send(\"[email protected]\",$headers,$body);
如果我将“ 1”行注释掉,则电子邮件的文本部分将按预期工作,并且可以看到为非HTML视图设置的内容。但是,如果我取消注释该行,则文本部分将失败。查看消息的来源,我可以看到文本部分始终存在。
这是与此问题相关的消息源部分:
Date: Thu,26 May 2011 10:39:24 -0500 (CDT)
From: From Address <[email protected]>
Subject: A MIME Email
To: [email protected]
Message-id: <[email protected]>
MIME-version: 1.0
Content-type: multipart/alternative;
boundary=\"=_e107860f353617028a0059317ce51c1f\"
Original-recipient: rfc822;[email protected]
--=_e107860f353617028a0059317ce51c1f
Content-transfer-encoding: quoted-printable
Content-Type: text/plain;
charset=ISO-8859-1
This is the text portion.
--=_e107860f353617028a0059317ce51c1f
Content-Type: multipart/related;
boundary=\"=_52fd7475fcf0abd310b6a38cd33f5c46\"
--=_52fd7475fcf0abd310b6a38cd33f5c46
Content-transfer-encoding: quoted-printable
Content-Type: text/html;
charset=ISO-8859-1
<html><body><p><img src=\'cid:3c0db5d0a50b8752771f64048f527338\' />This is th=
e HTML portion.</p></body></html>
--=_52fd7475fcf0abd310b6a38cd33f5c46
Content-transfer-encoding: base64
Content-ID: <3c0db5d0a50b8752771f64048f527338>
Content-Type: image/png;
name=background.png
Content-disposition: inline;
filename=background.png
iVBORw0KGgoAAAANSUhEUgAAAAEAABOICAYAAABwnAfKAAAAkUlEQVR42u3WSwrAIAwFwND7X9d1
eoHSb9TSzmYQSV5AXCRaa7lEROySJ+8uFd+8q2l73FEdkJNSRgR07q0uuVncJWBY6I9OWy85bKRB
7xo04TN8/vTO0OriziWFvcMCJqTMCui8rj5fuyMz43i1BwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAIB/swItzir5J/ImiQAAAABJRU5ErkJggg==
--=_52fd7475fcf0abd310b6a38cd33f5c46--
--=_e107860f353617028a0059317ce51c1f--
我对如何解决这个问题不知所措。任何机构都遇到类似问题或有任何建议吗?
解决方法
它是您的邮件阅读器。如果启用了HTML邮件,它将隐藏文本邮件。在gmail中,您可以查看详细信息,也可以在纯文本电子邮件阅读器中查看它