在 phpmailer 中设置附件的编码 [英] setting encoding for attachment in phpmailer

查看:65
本文介绍了在 phpmailer 中设置附件的编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 phpmailer 发送月度报告.

I am using phpmailer to send a monthly report.

它包括 € 符号.因此我需要将编码设置为 utf-8.我在这里遇到了问题.

It includes the € sign. Thus I need to set encoding to utf-8. I ran into a problem here.

没有这样的编码:

$mail->addStringAttachment($csvstring, $fileName);

邮件已发送,但在附件中没有显示 € 符号

the mail gets sent but in the attachment the € sign does not show up

当我尝试添加编码时:

$mail->addStringAttachment($csvstring, $fileName,  "utf-8", "text/csv");

邮件已发送,但正文和附件不存在.我试着查了一下,但似乎文档很少.

The mail is sent but body and attachment are not present. I tried looking it up but there seems to be very little documentation.

我是否遗漏了显而易见的东西?

Am I missing the obvious?

推荐答案

您感到困惑.EncodingCharSet 是两个不同的东西.通常字符集不会影响附件,因为它们通常是 base-64 编码的,因此只有 7 位.

You're getting confused. Encoding and CharSet are two different things. Generally the charset does not affect attachments because they are usually base-64 encoded, and thus are only 7-bit.

您可以设置一个整体的CharSet编码 用于整个邮件,但您可以覆盖每个附件的整体编码.

You can set an overall CharSet and an Encoding for your entire message, but you can override the overall encoding for each attachment.

附加内容的正确方法,根据 文档:

The correct way to attach your content, as per the docs:

$mail->addStringAttachment($csvstring, $fileName, 'base64', 'text/csv');

使用这种模式,附件将保留您传递给它的确切二进制内容 - 如果您仍然遇到字符问题,则是源数据的问题,而不是导致问题的发送.

With that pattern, the attachment will retain the exact binary content you pass into it - if you still have trouble with characters, it's a problem with the source data, not the sending that's causing it.

这篇关于在 phpmailer 中设置附件的编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆