您好,欢迎访问一九零五行业门户网

PHPMailer发送邮件中文附件名乱码的解决办法

$mail->addattachment($attach, $attach);
复制代码
发送过去的附件文件名将会是乱码,如果不指定:
$mail->addattachment($attach, $attach);
复制代码
发送过去的文件名中的中文直接没有了,变成了“.txt”。
解决办法一
打开class.phpmailer.php,在大概第1007行左右,函数addattachment中,有一句:
//$filename = basename($path);if (false === strpos($path, ‘/’))$filename = $this->encodeheader($path);else$filename = $this->encodeheader(substr($path, strrpos($path, ‘/’) + 1));
复制代码
解决办法二
如果想设置文件名为中文,则在调用addattachment时提供中文的name参数(第二个参数)。比如
$mail->addattachment(‘temp/2011/test.rar’, ‘测试.rar’);
复制代码
其它问题:发送中文邮件的时候,中文会出现乱码
乱码的产生大概是在将邮件标题转成几个小的=?utf-8?b?...?=时,可能是无意中把中文给截断了产生的,修改第1185行:
$maxlen = 75 - 7 - strlen($this->charset);
复制代码
改成:
$maxlen = 75000 - 7 - strlen($this->charset);
复制代码
附,phpmailer邮件发送类v5.1下载地址。
其它类似信息

推荐信息