Home  >  Article  >  Backend Development  >  PHP mail function sends mail and garbled code solution

PHP mail function sends mail and garbled code solution

WBOY
WBOYOriginal
2016-07-25 09:00:30863browse
When using the mail function in PHP code to send emails, sometimes there will be garbled characters. In this case, adding a specific encoding method can solve the problem.

Full code.

<?php
/**
 * mail函数发送邮件 乱码问题
 * 整理 by http://bbs.it-home.org
*/
$to = 'sales@zui88.com';
$subject = "=?UTF-8?B?".base64_encode('程序员之家,欢迎大家的光临。')."?=";
$message = "
用户姓名:{$_POST['name']}\n
用户邮箱:{$_POST['email']}\n
用户电话:{$_POST['contact']}\n
留言内容:{$_POST['content']}
";
$headers = 'From: test@jbxue.com' . "\r\n" .
'Reply-To: admin@jbxue.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";

mail($to, $subject, $message, $headers);
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn