Phpmailer Send mail Chinese attachment name is garbled

Source: Internet
Author: User
Tags rar strlen

For example, the attachment we are sending is "test. txt", if you want to force the use of the specified file name when you add the attachment:

$mail->addattachment ($attach, $attach);
Then send the past attachment file name will be garbled, if not specified:

$mail->addattachment ($attach, $attach);
Then send the previous file name in the Chinese simply did not, became a ". txt".


Solutions

Open class.phpmailer.php, in about 1007th line, function addattachment, there is a sentence

The code is as follows Copy Code

$filename = basename ($path);
if (false = = = Strpos ($path, '/'))
$filename = $this->encodeheader ($path);
Else
$filename = $this->encodeheader (substr ($path, Strrpos ($path, '/') + 1));


Solution II

If you want to set the file name to Chinese, the name parameter (the second argument) in Chinese is provided when AddAttachment is invoked.
Like what

The code is as follows Copy Code
$mail->addattachment (' Temp/2011/test.rar ', ' Test. rar ');

Other questions: When sending Chinese mail, Chinese will appear garbled

I looked at the source code, garbled generated is probably in the mail heading into a few small =?utf-8? B?...? = When, may be accidentally cut off the Chinese to produce, so my modification is simpler and slightly softer, modify line 1185th:

  code is as follows copy code

$maxlen = 75 -7-strlen ($this->charset);
Change to:
$maxlen = 75000-7-strlen ($this->charset);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.