doulan8152 2013-11-09 01:34
浏览 50

PHP邮件头中添加了额外的空格

I'm sending a multipart HTML email using PHP's mail() function. In my Postfix configuration I have my SMTP server set to Amazon's SES. Here is the PHP for sending the email:

$boundary = uniqid("HTMLDEMO");

$headers  = "From: me@mydomain.com
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: multipart/alternative; boundary = ".$boundary."

";

// plain text
$content  = "--".$boundary."
" .
            "Content-Type: text/plain; charset=ISO-8859-1
" .
            "Content-Transfer-Encoding: base64

" .
            chunk_split(base64_encode($plaintext_message));

// HTML
$content .= "--".$boundary."
" .
            "Content-Type: text/html; charset=ISO-8859-1
" .
            "Content-Transfer-Encoding: text/html 

" .
            "<html><body>".$html_message."</body></html>";

//send message
mail($to, $subject, $content, $headers);

When I echo the message content, this is what I see in the browser:

--HTMLDEMO527d8d851e72f
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: base64

VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCB2ZXJzaW9uIQ==
--HTMLDEMO527d8d851e72f
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: text/html

<html><body><p>My message here.</p></body></html>

But when I view the message source in Gmail, I now see this (including the message headers):

From: me@mydomain.com
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary = HTMLDEMO527d8d851e72f
Message-ID: <blah-blah-blah@email.amazonses.com>
Date: Sat, 9 Nov 2013 01:19:02 +0000
X-SES-Outgoing: 2013.11.09-12.34.5.67

--HTMLDEMO527d8d851e72f

Content-Type: text/plain; charset=ISO-8859-1

Content-Transfer-Encoding: base64



VGhpcyBpcyB0aGUgcGxhaW4gdGV4dCB2ZXJzaW9uIQ==

--HTMLDEMO527d8d851e72f

Content-Type: text/html; charset=ISO-8859-1

Content-Transfer-Encoding: text/html

The multipart headers are now double-spaced, causing the HTML to display as plain text. SES is clearly modifying the message headers (it added Message-ID, Date, and X-SES-Outgoing), so could that also be the culprit for the extra spaces in the multipart headers? When I send an identical email from a non-Amazon server, it comes through normally and renders the HTML like it should.

Also, when I send it as a simple HTML email (not multipart), then it works just fine.

Thanks.

  • 写回答

1条回答 默认 最新

  • duanpo7796 2014-01-28 18:38
    关注

    I had got the same issue and I resolved it by changing the end of line character to ' ' instead of ' '.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题