PHPMailer: The ultimate solution to the problem of garbled text in the Mail title, sender and content

Source: Internet
Author: User
PHPMailer: The ultimate solution to the problem of garbled text in the Mail title, sender and content

  1. Function EncodeHeader ($ str, $ position = 'text', $ pl = 0 ){
  2. If ($ pl) return "=? ". $ This-> CharSet ."? B? ". Base64_encode ($ str )."? = ";

A parameter that is defined for this function.

Naturally, you need to modify the parameters of all the places where this function is called. Search: EncodeHeader (you need to modify all the following methods:

  1. $ Result. = $ this-> HeaderLine ("Subject", $ this-> EncodeHeader (trim ($ this-> Subject )));

Changed:

  1. $ Result. = $ this-> HeaderLine ("Subject", $ this-> EncodeHeader (trim ($ this-> Subject), 'text', 1 ));

The third reference is defined as 1, so that we can call the judgment statement in the function we changed.

Now, remember to set CharSet = UTF8 when calling this class. In this way, this judgment statement can be converted to UTF8 without garbled characters. It can be written as follows:

  1. $ Mail = new PHPMailer ();
  2. $ Mail-> CharSet = "utf8 ";

Second, fix the garbled email Title. Subject is the title of the processed Email. you need to find this location. It's called like mine.

  1. $ Mail = new PHPMailer ();
  2. $ Mail-> Subject = "XX title ";

In this case, change it to the following:

  1. $ Mail-> Subject = "=? UTF-8? B? ". Base64_encode (" XX title ")."? = ";

It's also transcoding.

Third: the basic principle of Fixing garbled characters in other places is the same as that of the second solution. FromName is used to process the sender. Find the sender's name: I wrote it like this:

  1. $ Mail = new PHPMailer ();
  2. $ Mail-> FromName = "=? UTF-8? B? ". Base64_encode (" yellow card online customer message ]")."? = ";

If you can solve the above three problems, Phpmailer can basically solve the garbled problem when sending a Chinese email.

Appendix: an example code for modifying the complete phpmailer email sending: http://file.jbxue.com/code/201304/phpmailer_lyb_jbxue.com.zip.

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.