发送 PEAR Mail_Mime 电子邮件时,邮件 html 中缺少点 (.)

dot(.)s are missing here & there in the mail html while sending PEAR Mail_Mime emails

我正在使用 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);

我在通过此代码发送邮件时遇到了一个奇怪的问题。我的电子邮件正文中有图片,有时图片不显示。当我调试问题时,我发现url图像中缺少.。但是,如果我在发送行之前打印邮件(正如我在代码中注释掉的那样),它会完美地打印图像。

正确的图像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。

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

我很确定这是点填充造成的;因为点在电子邮件中用作特殊指示符。您可以在 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.

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

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

这是它的例子 -

     // 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']);