【问题标题】:PHPMailer attachments are showing up as base64-encoded textPHPMailer 附件显示为 base64 编码的文本
【发布时间】:2019-02-08 19:05:25
【问题描述】:

这是我的 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 中点击“显示原件”时看到的内容:

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。

有什么想法吗?

【问题讨论】:

  • 这里发生了一些奇怪的事情 - 你有两条消息粘在一起。这就是你的全部代码吗?
  • @Synchro - 确实如此。

标签: php email phpmailer email-attachments


【解决方案1】:

我知道可能是什么原因造成的 - PHPMailer 的 MIME 边界总是b1b2b3 开头 - 但你的以 _av 开头,所以我怀疑您有一些防病毒软件干扰了您的流量。

【讨论】:

【解决方案2】:

将 mime 类型(最后一个参数)设为“text/csv”并将文件名更改为 test.csv。还要提供一个逗号分隔的字符串作为第一个参数,使所有输入参数都有效。

【讨论】:

  • 好收获。我试图清理可用于识别我或我工作的公司的信息代码,但没有考虑 application/csv 位。无论如何,这没有什么区别。
猜你喜欢
  • 2018-01-16
  • 2018-04-18
  • 2020-10-15
  • 1970-01-01
  • 2014-06-21
  • 1970-01-01
  • 2016-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多