The PHP mail function sends the message header and the sender is garbled.

Source: Internet
Author: User

When you use the Mail method to send a letter, if the title or sender contains Chinese, it will cause garbled text, and the body will not. The solution is as follows

First Use the function Base64_encode ()? Using MIME base64 to encode data
The header string is encoded before the type example: =? UTF-8? B?
After the title string is added:? =
Mail header description Content-type? Prevent message body also garbled

First join the statement in the message header

If your site is GBK, the following utf-8 will be changed to GBK
$headers = ' mime-version:1.0 '. "\ r \ n";
$headers. = ' content-type:text/html; Charset=utf-8 '. "\ r \ n";

And then transfer the Chinese language where you need to use Chinese.

If your site is GBK, the following utf-8 will be changed to gb2312
such as title
$subject = "New password notification letter";
$subject = "=? UTF-8? B? ". Base64_encode ($subject). "? =";
such as sender
$headers. = ' From: =? UTF-8? B? '. Base64_encode ("XXX website"). ' =<service@apieye.com> '. "\ r \ n";

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.