Gmail 将邮件正文作为附件提取


Gmail picking up message body as an attachment

我有一个非常简单的电子邮件脚本,如下所示。当我向自己发送电子邮件时,它适用于所有客户端,除了 Gmail,其中邮件正文为空,并且会出现包含内容的 HTML 文件附件!

$headers = "From: Me <me@example.com>'r'n";
$headers .= "MIME-Version: 1.0'r'n";
$headers .= "Content-Type: text/html, charset=UTF-8'r'n";
$message = <<<EOM
<p>Hello Me,</p>
<p>This is a test message.</p>
<p>Regards,</p>
<p><strong>You</strong><br>example.com</p>'r'n
EOM;
mail("you@example.com'r'n", "Test Message'r'n", $message, $headers);

对此事的任何见解将不胜感激。

将标头更改为以下内容:

$headers = "From: Me <me@example.com>'r'n";
$headers .= 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "'r'n";

$headers = "From: Me <me@example.com>'r'n";
$headers .= 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";

您的标题格式不正确。

请参阅有关 PHP.net 的手册

  • http://php.net/manual/en/function.mail.php