Solution to Chinese garbled text of the phpmail Mail subject

Source: Internet
Author: User
When you use the following PHP statement to send an email, if the encoding is different from that of the email recipient, you will find that the email title is garbled while the email body is correct, how can we make the Mail title not garbled? $ Subjects... when you use the following PHP statement to send an email, if the encoding is different from that of the email recipient, you will find that the email title is garbled while the email body is correct, how can we make the Mail title not garbled?

$subject = stripslashes($the_post['Title']);  $headers = "MIME-Version: 1.0\r\n";  $headers .= "Content-type: text/plain; charset=utf-8\r\n";  $headers .= "Content-Transfer-Encoding: 8bit\r\n";  $message = stripslashes(strip_tags($the_post['Content']));  mail($to, $subject, $message, $headers);

First use the base64_encode () function-use MIME base64 to encode the data, and add the encoding type before the title string, for example: =? UTF-8? B ?, The title string is followed :? =, For example:

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

Add the above sentence to the code. in this way, the Chinese mail Title sent is not garbled, and the code is as follows:

 

The final solution is as follows:

Garbled Title: $ subject = "=? UTF-8? B? ". Base64_encode ('mailbox verification -- '. SITE_NAME )."? = ";

Garbled text, set header: charset = utf-8'

$headers = 'From: webmaster@webinno.cn' . "\r\n" .  'Content-type: text/html; charset=utf-8' . "\r\n" .  // 'Reply-To: webmaster@example.com' . "\r\n" .  'X-Mailer: PHP/' . phpversion();


Permanent link:

Reprint at will! Include the article address.

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.