The PHPmail () function garbled by code. The cause of this problem is that Content-type: texthtml; charsetutf-8 is missing in the header parameter of the mail () function, or charset is not UTF-8. We are using many foreign PHP programs.
Generally, this problem occurs because Content-type: text/html; charset = utf-8 is missing in the header parameter of the mail () function, or charset is not UTF-8. Many PHP programs outside China are not considered in Chinese at the beginning of development, so PHP mail () function garbled characters will appear when using Chinese.
Use the base64_encode () function to encode the data using MIME base64.
The header string is prefixed with the encoding type, for example: =? UTF-8? B?
Of course, if it is gb2312, then =? GB2312? B?
The title string is followed :? =
The following is an example of how to handle garbled PHP mail () functions:
- $ To = 'xinple @ example.com ';
- $ Subject = "=? UTF-8? B? ".
Base64_encode ('email title ')."? = ";
- $ Headers = 'Mime-Version: 100'. "rn ";
- $ Headers. = 'content-type:
Text/html; charset = utf-8 '. "rn ";
- // Additional headers
- $ Headers. = 'To: Xinple <
<A href = "mailto: xinple@example.com">
Xinple@example.com> '. "rn ";
- $ Headers. = 'from: Admin <
Admin@example.com> '. "rn ";
- $ Headers. = 'reply-To: Xinple <xinple @ example> '. "rn ";
- Mail ($ to, $ subject, $ message, $ headers );
The above is the specific solution for PHP mail () function garbled code, hope to help friends in need.
In general, this problem occurs because Content-type: text/html; charset = utf-8 is missing in the header parameter of the mail () function, or charset is not UTF-8. Many PHP programs abroad...