PHPMailer attachments are showing up as base64-encoded text

萝らか妹 提交于 2019-12-13 03:57:40

问题


Here's my PHP code:

$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();

Here's what it looks like in my Gmail inbox:

Here's what I want it to look like:

Here's what I see when I click on "Show original" in 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--

According to composer.lock I'm using v6.0.5.

Any ideas?


回答1:


I have an idea what might be causing this - PHPMailer's MIME boundaries always start with b1, b2, b3 - but yours starts with _av, so I suspect that you have some anti-virus software interfering with your traffic.




回答2:


Make the mime-type (last parameter) 'text/csv' and change the file name to test.csv. Also provide a comma delimited string as the first parameter to make all the input parameters valid.



来源:https://stackoverflow.com/questions/52154572/phpmailer-attachments-are-showing-up-as-base64-encoded-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!