Phpmailer send a message a summary of the solving methods of Chinese garbled problem

Source: Internet
Author: User
Tags php website
    1. $mail = new Phpmailer ();
Copy Code

2: Set the encoding of the message;

    1. $mail->charset= ' UTF-8 ';
Copy Code

Believe that a lot of friends are set to "GBK" or "GB2312", I started also, later learned that mail is internationalized, if you want to in the international mailbox like Gmail, such as the correct display of Chinese, please set the code to "UTF-8";

3,: Set the title code; Here may be asked, all set the encoding of the message, but also set the title code to do what. If you test a variety of mailboxes, you will find that the title of Chinese is garbled, yes, even if you set the $mail->charset= "UTF-8"; Since learning PHP should read more PHP manual or pay attention to php.net, the title garbled solution I was on the PHP website to find the answer to the hhtp://.www.php.net/mail. $mail->subject = "letter title"; instead $mail->subject = "=?utf-8?" B? ". Base64_encode ("letter title"). "? ="; " This encoding is designed so that binary data can be transmitted through a non-pure 8-bit transport layer, such as the body of an e-mail message. "(from PHP Manual Base64_encode ()) This way, the title of the Chinese garbled also resolved.

#---------------------attached, phpmailer send mail Chinese garbled problem

Phpmailer messages that are sent out by default may appear garbled. Web-based solution: Add a line

    1. $mail->charset = "UTF-8";
Copy Code

After testing, this method for 163 is available, but QQ mailbox will become garbled, and QQ mailbox in the default situation is no problem. The right approach:

    1. $mail->charset = "GB2312";
Copy Code

Chinese is better with GB2312. Tested only qq,163 other tests were not tested.

2012-11-5 Update: $mail->charset This method should set the encoding to be the one that you refer to the page of the Phpmailer class, For example, in 1.php to refer to the class to send mail, you need to set to 1.php the encoding type of the file, how to view the file encoding, this question do not ask. Of course, externally referenced content is best to unify the file encoding as well.

This is all, hope that the above content can help you solve phpmailer Chinese mail sent garbled problem. The programmer's home, wish everybody to study happily.

  • 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.