PHP send UTF-8 code Chinese mail title garbled solution

Source: Internet
Author: User

When we use the following PHP statement to send Chinese e-mail, we will find that the title of the message is garbled, and the message body is correct, how to make the message title is not garbled?

$subject = stripslashes ($the _post[' Title '));
$headers = "Mime-version:1.0rn";
$headers. = "Content-type:text/plain; Charset=utf-8rn ";
$headers. = "CONTENT-TRANSFER-ENCODING:8BITRN";
$message = Stripslashes (strip_tags ($the _post[' Content '));
Mail ($to, $subject, $message, $headers);

First Use function Base64_encode ()-encode data using MIME base64
The header string is encoded before the type example: =? UTF-8? B?
After the title string is added:? =

For example:

$subject = "=? UTF-8? B? ". Base64_encode ($subject). "? =";

Add the above sentence to the code, so that the Chinese message headers sent are not garbled.



</

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.