【发布时间】:2015-09-22 12:27:27
【问题描述】:
我正在使用 PEAR 的 mail 和 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);
通过此代码发送邮件时,我遇到了一个奇怪的问题。我在电子邮件正文中有图像,有时图像不显示。当我调试问题时,我发现图像 url 中缺少 .。但是,如果我在发送行之前打印邮件(正如我在代码中注释掉的那样),它会完美地打印出图像。
正确的图片网址: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; 是原始的,它在发送时更改为line-heigth:15;。
基本上它只是删除电子邮件 HTML 中的 .。
【问题讨论】:
-
$html和$body的值是多少? -
实际上它有点大的 html 模板,虽然我会用相关的图像部分编辑它,但我不能把它放在问题中,@DaveChen 请检查编辑的问题
-
有趣...您为 MS-Outlook 发送不同的电子邮件?您如何提前知道哪个收件人使用哪个电子邮件客户端?
-
@arkascha 不,就像我在模板中使用的 Outlook 代码
<!--[if gte mso 9]>和非 Outlook<![if !mso]>一样,所以当它在客户端查看时,它采用正确的代码 -
所以即使在今天,仍然需要旧的东西来为每个 MS 产品创建特殊的解决方案? 叹息