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.