PHPMailer 附件显示为 base64 编码的文本
PHPMailer attachments are showing up as base64-encoded text
这是我的 PHP 代码:
$mail = new PHPMailer();
$mail->AddAddress('neubert@neubert.com');
$mail->SetFrom('neubert@neubert.com');
$mail->Subject = 'Attachment Test ' . mt_rand(1, 10000000);
$mail->Body = 'See attached!';
$mail->AddStringAttachment('hello, world!', 'test.txt', 'base64', 'application/csv');
$mail->Send();
这是我的 Gmail 收件箱中的样子:
这是我想要的样子:
这是我在 Gmail 中点击 "Show original" 时看到的内容:
Content-Type: multipart/alternative; boundary="_av-HS21mQOZlMv59VDZAuEczg"
--_av-HS21mQOZlMv59VDZAuEczg
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
This is a multi-part message in MIME format.
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8 Content-Type: text/plain;
charset=us-ascii See attached!
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8 Content-Type:
application/csv; name="test.txt" Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=test.txt aGVsbG8sIHdvcmxkIQ==
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8--
--_av-HS21mQOZlMv59VDZAuEczg
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
This is a multi-part message in MIME format.
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8
Content-Type: text/plain; charset=us-ascii
See attached!
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8
Content-Type: application/csv; name="test.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=test.txt
aGVsbG8sIHdvcmxkIQ==
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8--<img src="https://mandrillapp.com/track/open.php?u=30776766&id=8ee95f6ae4b345d2a87af6f4ea043ca2" height="1" width="1">
--_av-HS21mQOZlMv59VDZAuEczg--
根据 composer.lock 我正在使用 v6.0.5。
有什么想法吗?
制作 mime 类型(最后一个参数)'text/csv' 并将文件名更改为 test.csv。还提供一个逗号分隔的字符串作为第一个参数,以使所有输入参数有效。
我知道是什么原因造成的 - PHPMailer 的 MIME 边界 总是 以 b1
、b2
、b3
开头 - 但是你的以 _av
开头,所以我怀疑你有一些防病毒软件干扰了你的流量。
这是我的 PHP 代码:
$mail = new PHPMailer();
$mail->AddAddress('neubert@neubert.com');
$mail->SetFrom('neubert@neubert.com');
$mail->Subject = 'Attachment Test ' . mt_rand(1, 10000000);
$mail->Body = 'See attached!';
$mail->AddStringAttachment('hello, world!', 'test.txt', 'base64', 'application/csv');
$mail->Send();
这是我的 Gmail 收件箱中的样子:
这是我想要的样子:
这是我在 Gmail 中点击 "Show original" 时看到的内容:
Content-Type: multipart/alternative; boundary="_av-HS21mQOZlMv59VDZAuEczg"
--_av-HS21mQOZlMv59VDZAuEczg
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
This is a multi-part message in MIME format.
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8 Content-Type: text/plain;
charset=us-ascii See attached!
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8 Content-Type:
application/csv; name="test.txt" Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=test.txt aGVsbG8sIHdvcmxkIQ==
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8--
--_av-HS21mQOZlMv59VDZAuEczg
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: 7bit
This is a multi-part message in MIME format.
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8
Content-Type: text/plain; charset=us-ascii
See attached!
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8
Content-Type: application/csv; name="test.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=test.txt
aGVsbG8sIHdvcmxkIQ==
--b1_sXvhvmroccaUM1u8XDL1OMveVh8ZiFheK8opqb2i3o8--<img src="https://mandrillapp.com/track/open.php?u=30776766&id=8ee95f6ae4b345d2a87af6f4ea043ca2" height="1" width="1">
--_av-HS21mQOZlMv59VDZAuEczg--
根据 composer.lock 我正在使用 v6.0.5。
有什么想法吗?
制作 mime 类型(最后一个参数)'text/csv' 并将文件名更改为 test.csv。还提供一个逗号分隔的字符串作为第一个参数,以使所有输入参数有效。
我知道是什么原因造成的 - PHPMailer 的 MIME 边界 总是 以 b1
、b2
、b3
开头 - 但是你的以 _av
开头,所以我怀疑你有一些防病毒软件干扰了你的流量。