我使用PEAR的邮件和mail_mime包和示例代码发送邮件,如下所示:
$sendStart=array(); require_once('Mail.PHP'); require_once('Mail/mime.PHP'); $sendStart['mail'] =& Mail::factory('mail'); $sendStart['mime'] = new Mail_mime("\n"); $sendStart['mime']->setHTMLBody($html); $sendStart['headers']['Subject']=$title; $sendStart['headers']['X-SMTPAPI']='{"category": ["MailID-XXX"]}'; $body=$sendStart['mime']->get(array( 'html_charset'=>'UTF-8','text_charset'=>'UTF-8','head_charset'=>'UTF-8' )); //echo ($sendStart['mime']->_htmlbody); exit; $sendStart['mail']->send('xxx@example.com',$sendStart['mime']->headers($sendStart['headers']),$body);
通过这段代码发送邮件时,我面临着一个奇怪的问题.电子邮件正文中有图像,有时图像不显示.当我调试问题时,我发现.在图像网址中缺少.但是如果我在发送行之前打印邮件(正如我在代码中注释的那样),它将完美地打印图像.
正确的图片网址:http://www.domain.com/image.png
在邮件:http://www.domaincom/image.png或http://www.domain.com/imagepng …等
具有以下图像的HTML代码的一部分:
<table cellpadding="0" cellspacing="0" border="0" class="image-table image-2" align="center" style="float:none;margin-left:auto;margin-right:auto;text-align:left;"> <tbody> <tr> <td class="element" style="text-align: left;height: auto;overflow: hidden;-webkit-text-size-adjust: none;"> <!--[if gte mso 9]><img alt="Placeholder Image" src="http://www.domain.com/image.png" style="outline: none; text-decoration: none; display: block; clear: none; float: none; margin-left: auto; margin-right: auto;display:none; mso-hide: none;" align="center" width="394"><![endif]--><![if !mso]><!-- --><img alt="Placeholder Image" src="http://www.domain.com/image.png" style="outline: none;text-decoration: none;display: block;clear: none;float: none;width: 100%;height: auto;max-width: 394px;margin-left: auto;margin-right: auto;*width: 394px;-ms-interpolation-mode: bicubic;" align="center"><!--<![endif]--> </td> </tr> </tbody> </table>
而且非常奇怪的是它在Outlook中正常显示,但在其他客户端中显示不正确,因为outlook我有单独的代码(根据代码).
有人有任何想法如何调试问题或任何关于这个问题的评论.
编辑:
这个问题与任何特定的标签无关(虽然我使用图像标签来解释),我在几个地方体验到,如风格.
例如:line-heigth:1.5;是原来的,它变化为线 – 高:15;同时发送.
解决方法
我很确定这是由点填充造成的;因为该点被用作电子邮件中的特殊指示符.您可以在
the rfc中阅读有关这一点的内容(重点在于):
To allow all user composed text to be transmitted transparently,the following procedures are used:
- Before sending a line of mail text,the SMTP client checks the first character of the line. If it is a period,one additional period is inserted at the beginning of the line.
- When a line of mail text is received by the SMTP server,it checks the line. If the line is composed of a single period,it is treated as the end of mail indicator. If the first character is a period and there are other characters on the line,the first character is deleted.
您用来撰写这些电子邮件的客户端似乎没有实现第一个过程,而发送邮件的服务器却实现了它;导致点消失.
修复将是让您的客户端实现填充.