Home >Backend Development >PHP Tutorial >Solution to phpmailer Chinese garbled problem_PHP tutorial
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;
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())