Home  >  Article  >  Backend Development  >  Solution to phpmailer Chinese garbled problem_PHP tutorial

Solution to phpmailer Chinese garbled problem_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:32:03782browse

1: Open the phpmailer core file class.phpmailer.php and change public $CharSet = ‘iso-8859-1′; to public $CharSet = ‘UTF-8′;

As for why you need to change 'iso-8859-1' to 'UTF-8', please Google or Baidu to find out 'iso-8859-1'.

2: Set the encoding of the email;

Copy code The code is as follows:
$mail = new PHPMailer();
$mail->Charset='UTF- 8′;

I believe that many friends have set it to "GBK" or "GB2312". I did the same at first. Later I learned that Mail is international. If you want to correctly display Chinese in international mailboxes like Gmail, please change Encoding set to "UTF-8";

3,: Set the title encoding;

Some people may ask here, after setting the encoding of the email, what is the purpose of setting the title encoding. . . If you have tested multiple mailboxes, you will find that the Chinese title is garbled. Yes, even if you set $mail->Charset=”UTF-8″;
Since you are learning PHP, you should read more PHP manuals or Pay attention to php.net. I found the solution to the garbled title on the official php website: hhtp://.www.php.net/mail.
$mail->Subject = "Letter Title"; changed to $mail->Subject = "=?utf-8?B?" . base64_encode("Letter Title") . "?=";
"This encoding is designed to enable binary data to be transmitted over a non-pure 8-bit transport layer, such as the body of an email." (from the PHP manual base64_encode())

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/759335.htmlTechArticle1: Open the phpmailer core file class.phpmailer.php and set public $CharSet = 'iso-8859-1′ ; Change to public $CharSet = 'UTF-8'; As for why you need to change 'iso-8859-1' to 'U...
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