Home  >  Article  >  Backend Development  >  Solution to phpmailer Chinese garbled problem

Solution to phpmailer Chinese garbled problem

WBOY
WBOYOriginal
2016-07-25 08:53:24794browse
  1. $mail = new PHPMailer();
  2. $mail->Charset='UTF-8′;
Copy code

I believe many friends are set to "GBK" or "GB2312" Yes, I was the same at first, but later I learned that Mail is internationalized. If you want to display Chinese correctly in international mailboxes like Gmail, please set the encoding to "UTF-8";

3. Set 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 learning PHP, you should read more PHP manuals or pay attention to php.net. I found the solution to the garbled title on the PHP official website: hhtp://.www.php.net/mail.

  1. $mail->Subject = "Letter Title"; changed to $mail->Subject = "=?utf-8?B?" . base64_encode("Letter Title") . "?=" ;
Copy code

"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() )



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