Home  >  Article  >  Backend Development  >  Solution to garbled Chinese attachment names in emails sent by PHPMailer

Solution to garbled Chinese attachment names in emails sent by PHPMailer

WBOY
WBOYOriginal
2016-07-25 08:59:421475browse
  1. $mail->AddAttachment($attach, $attach);
Copy code

The attachment file name sent will be garbled, if not specified:

  1. $mail->AddAttachment($attach, $attach);
Copy the code

The Chinese in the file name sent is gone and becomes ".txt".

Solution 1

Open class.phpmailer.php. Around line 1007, in the function AddAttachment, there is a sentence:

  1. //$filename = basename($path);
  2. if (false === strpos($path, '/'))
  3. $filename = $this->EncodeHeader($path);
  4. else
  5. $filename = $this->EncodeHeader(substr($path, strrpos($path, '/') + 1));
Copy code

Solution 2

If you want to set the file name to Chinese, provide the Chinese name parameter (the second parameter) when calling AddAttachment. for example

  1. $mail->AddAttachment('temp/2011/test.rar', 'test.rar');
Copy code

Other problems: When sending Chinese emails, Chinese will appear Garbled code

The garbled characters are probably generated when the email title is converted into several small ones =?utf-8?B?...?=, and the Chinese may be accidentally truncated. Modify line 1185:

  1. $maxlen = 75 - 7 - strlen($this->CharSet);
Copy the code

and change it to:

  1. $maxlen = 75000 - 7 - strlen($this->CharSet);
Copy code

Attached, PHPMailer email sending class V5.1 download address.



Statement:
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