Solution to PHPmail () function garbled code _ PHP Tutorial

Source: Internet
Author: User
The PHPmail () function garbled by code. The cause of this problem is that Content-type: texthtml; charsetutf-8 is missing in the header parameter of the mail () function, or charset is not UTF-8. We are using many foreign PHP programs.

Generally, this problem occurs because Content-type: text/html; charset = utf-8 is missing in the header parameter of the mail () function, or charset is not UTF-8. Many PHP programs outside China are not considered in Chinese at the beginning of development, so PHP mail () function garbled characters will appear when using Chinese.

Use the base64_encode () function to encode the data using MIME base64.
The header string is prefixed with the encoding type, for example: =? UTF-8? B?
Of course, if it is gb2312, then =? GB2312? B?
The title string is followed :? =

The following is an example of how to handle garbled PHP mail () functions:

 
 
  1. $ To = 'xinple @ example.com ';
  2. $ Subject = "=? UTF-8? B? ".
    Base64_encode ('email title ')."? = ";
  3. $ Headers = 'Mime-Version: 100'. "rn ";
  4. $ Headers. = 'content-type:
    Text/html; charset = utf-8 '. "rn ";
  5. // Additional headers
  6. $ Headers. = 'To: Xinple <
    <A href = "mailto: xinple@example.com">
    Xinple@example.com> '. "rn ";
  7. $ Headers. = 'from: Admin <

    Admin@example.com> '. "rn ";
  8. $ Headers. = 'reply-To: Xinple <xinple @ example> '. "rn ";
  9. Mail ($ to, $ subject, $ message, $ headers );

The above is the specific solution for PHP mail () function garbled code, hope to help friends in need.


In general, this problem occurs because Content-type: text/html; charset = utf-8 is missing in the header parameter of the mail () function, or charset is not UTF-8. Many PHP programs abroad...

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.