Home > php教程 > php手册 > body text

PHPMailer发送邮件中文附件名是乱码

WBOY
Release: 2016-05-25 16:49:14
Original
2003 people have browsed it

使用了PHPMailer发送邮件的朋友带中文附件名时会出现乱码,下面我来介绍一个解决办法,比如我们要发送的附件是"测试.txt",如果在添加附件的时候强制使用指定文件名的方式:

$mail->AddAttachment($attach, $attach); 

那么发送过去的附件文件名将会是乱码,如果不指定:

$mail->AddAttachment($attach, $attach); 

那么发送过去的文件名中的中文干脆没了,成了".txt"。

解决办法:如果想设置文件名为中文,则在调用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);


本文地址:

转载随意,但请附上文章地址:-)

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!