【问题标题】:dot(.)s are missing here & there in the mail html while sending PEAR Mail_Mime emails发送 PEAR Mail_Mime 电子邮件时,邮件 html 中到处都缺少点 (.)
【发布时间】: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.pnghttp://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 代码 &lt;!--[if gte mso 9]&gt; 和非 Outlook &lt;![if !mso]&gt; 一样,所以当它在客户端查看时,它采用正确的代码
  • 所以即使在今天,仍然需要旧的东西来为每个 MS 产品创建特殊的解决方案? 叹息

标签: php email pear mime


【解决方案1】:

使用PHPMailer,生活会轻松很多。

【讨论】:

  • 由于某些原因,我无法更改电子邮件系统。但感谢您的建议。
【解决方案2】:

我很确定这是由点填充引起的;因为圆点在电子邮件中用作特殊指示符。您可以在 the rfc 中阅读有关此内容的内容(已添加重点):

为了让所有用户编写的文本能够透明地传输,使用了以下过程:

  • 在发送一行邮件文本之前,SMTP 客户端会检查该行的第一个字符。如果是句号,则在行首插入一个附加句号。
  • 当 SMTP 服务器接收到一行邮件文本时,它会检查该行。如果该行由单个句点组成,则将其视为邮件结束指示符。 如果第一个字符是句号并且该行还有其他字符,则删除第一个字符。

您用来撰写这些电子邮件的客户端似乎没有实现了第一个过程,而它发送邮件的服务器确实实现了它;导致点消失。

解决方法是让您的客户端实现填充。

【讨论】:

  • 我也面临着完全相同的问题。你能告诉我如何以编程方式解决这个问题。请给我一个你如何修复的例子。
【解决方案3】:

这是它的例子 -

     // Set up the headers that will be included in the email.
    $recipient = 'someemail@gmail.com';
    $from = 'someemail1@gmail.com';

    $headers = array(
      'To'            => $recipient,
      'From'          => $from,
      'Return-Path'   => $from,
      'Reply-To'      => $replyto, //based on your need
      'Subject'       => $subject,
      'Errors-To'     => '<<a href="mailto:errors@example.com">errors@example.com</a>>',
      'MIME-Version'  => '1.0',
    );

    // Set up parameters for both the HTML and plain text mime parts.
    $textparams = array(
      'charset'       => 'utf-8',
      'content_type'  => 'text/plain',
      'encoding'      => 'quoted/printable',
    );
    $htmlparams = array(
      'charset'       => 'utf-8',
      'content_type'  => 'text/html',
      'encoding'      => 'quoted/printable',
    );

    // Create the email itself. The content is blank for now.
    $email = new Mail_mimePart('', array('content_type' => 'multipart/alternative'));

    // Add the text and HTML versions as parts within the main email.
    $textmime = $email->addSubPart($textbody, $textparams);
    $htmlmime = $email->addSubPart($htmlbody, $htmlparams);

    // Get back the body and headers from the MIME object. Merge the headers with
    // the ones we defined earlier.
    $final = $email->encode();
    $final['headers'] = array_merge($final['headers'], $headers);

    // Perform the actual send.
    $smtp_params = array();
    $smtp_params['host'] = '127.0.0.1';
    $smtp_params['port'] = '25';
    $smtp_params['persist'] = TRUE;

    $mail =& Mail::factory('smtp', $smtp_params);
    $status = $mail->send($recipient, $final['headers'], $final['body']);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-04
    • 1970-01-01
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    • 2014-09-13
    • 2012-01-03
    • 1970-01-01
    相关资源
    最近更新 更多