Solve PHPmail to send UTF-8 Chinese mail garbled

Source: Internet
Author: User
Tags mail code
Here, I will solve a problem that many people may have encountered and are confused and do not know how to do it. How can I send a Chinese email without garbled characters? Here I will show you how to send a Chinese email in UTF-8 encoding format. This document does not contain Chinese emails in GBK or GB2312 encoding format. It is actually very easy to solve this problem. Please read the following generation

Here, I will solve a problem that many people may have encountered and are confused and do not know how to do it. How can I send a Chinese email without garbled characters? Here I will show you how to send a Chinese email in UTF-8 encoding format. This document does not contain Chinese emails in GBK or GB2312 encoding format. It is actually very easy to solve this problem. Please read the following generation

Here, I will solve a problem that many people may have encountered and are confused and do not know how to do it.

How can I send a Chinese email without garbled characters?

Here I will show you how to send a Chinese email in UTF-8 encoding format. This document does not contain Chinese emails in GBK or GB2312 encoding format.

It is actually very easy to solve this problem. Read the following code. Reference your email title as '=? UTF-8? B? 'And '? = '.

You can use HTML to edit your email content, but do not forget to use UTF-8 encoding.

Email Header content
MIME-Version: 1.0MIME Version. This header field uses a Version number to indicate the MIME-compliant Version of a message in the message. The current version is 1.0.
Content-Type: text/html; charset = UTF-8; supports HTML format, UTF-8 encoding.

Content-Transfer-Encoding: 8Bit

Content transmission code, which is an 8-bit ASCII code.

X-Mailer: LixiPHP

The system name of the email you want to send.

From: =? UTF-8? B? What is the sender's name? =
 
  
Email address sent
 
To: =? UTF-8? B? Recipient's name? =
 
  
Accepted email address
 
Subject: =? UTF-8? B? Mail title? = Mail title
By viewing the source code of the email, I can see:
PHP Mail Code

Public function send_email ($ to, $ from, $ subject, $ message, $ fromname = ", $ toname = "){

If ($ toname ){

$ To = '=? UTF-8? B? '. Base64_encode ($ toname ).'? = '. $;

}

If ($ fromname ){

$ From = '=? UTF-8? B? '. Base64_encode ($ fromname ).'? = '. $ From;

}

$ Headers = 'from: '. $ From. "\ r \ n ".

"MIME-Version: 1.0 \ r \ n ".

"Content-Type: text/html; charset = UTF-8; format = flowed \ r \ n ".

"Content-Transfer-Encoding: 8Bit \ r \ n ".

'X-Mailer: PHP/'. phpversion ();

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

// Send email

Mail ($ to, $ subject, $ message, $ headers );

}

This is a simple UTF-8 mail sending function, it is the header information in the Chinese through encryption to solve the problem of Chinese garbled.

(...)
Read the rest of solve PHP mail Send UTF-8 Chinese mail garbled (3 words)

©Lixiphp for LixiPHP, 2013. | Permalink | No comment | Add to del. icio. us
Post tags: mail, PHP, UTF8

Feed enhanced by Better Feed from Ozh

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.