【发布时间】:2014-05-02 02:49:04
【问题描述】:
我在通过 Wordpress 函数 wp_mail 发送多部分电子邮件时遇到了一些问题,它基本上只是 PHP Mailer 的包装器。
在 OS X Mail.app 中,邮件显示正常。在 Thunderbird 中,什么都不会显示,而 Google Mail 会显示一个名为“noname”的附件,大小为 1 KB。
我的猜测是它与编码有关,因为我注意到边界根本没有显示在电子邮件的标题中,而它出现在我收到的其他电子邮件的标题中。此外,似乎存在某种 Content-Transfer-Encoding 不匹配?
这些是标题的重要位:
To: email@address.com
Subject: Testsubject
X-PHP-Originating-Script: 10029:class-phpmailer.php
Date: Mon, 24 Mar 2014 15:52:59 +0000
From: WordPress <wordpress@example.com>
Message-ID: <ab7dd25d45c2d5be71df1e592bb0ab96@www.example.com>
X-Priority: 3
X-Mailer: PHPMailer 5.2.4 (http://code.google.com/a/apache-extras.org/p/phpmailer/)
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: multipart/alternative; charset=UTF-8
--1234567890
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Text Plain
--1234567890
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<b>HTML E-Mail</b>
--1234567890--
在其他正确显示的 HTML 电子邮件中,我可以清楚地从标题中读取边界。另外,Content-Transfer-Encoding 也不同。
Content-Type: multipart/alternative; boundary="--==_mimepart_532c53995fed2_5f733fb4b5966cd0158292"; charset="UTF-8"
Content-Transfer-Encoding: 7bit
在我的 PHP 脚本中,邮件是这样编译的:
$to = 'email@address.com';
$subject = 'Testsubject';
$headers = 'Content-Type: multipart/alternative; charset=UTF-8; boundary="1234567890"' . "\r\n\r\n";
$message = '--1234567890' . "\r\n";
$message .= 'Content-Type: text/plain; charset=UTF-8' . "\r\n";
$message .= 'Content-Transfer-Encoding: 7bit' . "\r\n\r\n";
$message .= 'Text Plain' . "\r\n\r\n";
$message .= '--1234567890' . "\r\n";
$message .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
$message .= 'Content-Transfer-Encoding: 7bit' . "\r\n\r\n";
$message .= '<b>HTML E-Mail</b>' . "\r\n\r\n";
$message .= '--1234567890--';
wp_mail( $to, $subject, $message, $headers );
你在这里看到什么让你印象深刻的东西吗?为什么 Thunderbird/Google Mail 中根本不显示电子邮件正文?
目前我在想可能是服务器配置错误或类似情况,但 Mail.app 正确显示邮件的事实并不适合。
【问题讨论】:
-
边问:你能用 7bit 编码的 UTF-8 吗?!
标签: php wordpress email html-email phpmailer