我想用utf8编码发送这封电子邮件的信息。
我能为此做些什么?
include 'functions.php';
$name = stripslashes($_POST['name']);
$email = trim($_POST['email']);
$subject = stripslashes($_POST['subject']);
$message = stripslashes($_POST['message']);
$cap=strtoupper($_POST['cap']);
$error = '';
$mail = mail(WEBMASTER_EMAIL,$subject,$message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());我可以在utf8中发送什么?
发布于 2012-12-06 05:23:27
您可以在电子邮件标题中指定编码,如下所示:
$mail = mail(WEBMASTER_EMAIL,$subject,$message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."Content-type: text/html; charset=UTF-8\r\n"
."X-Mailer: PHP/" . phpversion());发布于 2012-12-06 05:01:34
你可以使用php的utf8_encode函数。如下所示:
$message = utf8_encode(stripslashes($_POST['message']));这将存储在$message变量或任何其他变量中编码的字符串utf8。
编辑
如果您使用swiftmailer库,它将默认使用utf8编码。
发布于 2013-06-01 00:28:32
您需要在头文件中设置utf-8编码,并对主题进行编码,因为它很容易被破坏。我个人创建了自己的函数,它还添加了设置发送者地址的功能:
function mail_utf8 ($to, $subject='', $message='', $from='', $header='') {
if (preg_match("/\<html.*\>/i", $message))
$content_type = "html";
else
$content_type = "plain";
$header .= "\nMIME-Version: 1.0";
$header .= "\nContent-type: text/$content_type; charset=UTF-8";
if ($from)
$header .= "\nFrom: ".$from;
mail($to, "=?UTF-8?B?".base64_encode($subject)."?=", $message, trim($header));
}https://stackoverflow.com/questions/13732253
复制相似问题