我发现了你是如何做到这一点的,你需要在邮件本身以及邮件标题(主题等)和邮件中的消息的扩展名中设置 UTF-8。
这是一个向客户发送邮件并将副本发送给卖方的代码示例:
// send user an email with a confirmation
$firstname = $_POST['first_name'];
$lastname = $_POST['last_name'];
$to = filter_var($_POST['payer_email'], FILTER_SANITIZE_EMAIL);
$to2 = filter_var($_POST['your@email.com'], FILTER_SANITIZE_EMAIL);
$subject = "Tack för Ert köp! / Thank you for your order!";
$subject2 = "(COPY) Tack för Ert köp! / Thank you for your order!";
$headerFields = array(
'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
"Subject: =?UTF-8?Q?".imap_8bit($subject)."?=",
"From: {$to}",
"MIME-Version: 1.0",
"Content-Type: text/html;charset=utf-8"
);
$headerFields2 = array(
'Date: ' . date('r', $_SERVER['REQUEST_TIME']),
"Subject: =?UTF-8?Q?".imap_8bit($subject2)."?=",
"From: {$to}",
"MIME-Version: 1.0",
"Content-Type: text/html;charset=utf-8"
);
$message = "$firstname $lastname, $payer_email <br />
MESSAGE TO CUSTOMER;
$message2 = "$firstname $lastname, $payer_email <br />
MESSAGE TO CUSTOMER
(NOTE: THIS IS A COPY)";
mail($to, $subject, $message, implode("\r\n", $headerFields));
mail($to2, $subject2, $message2, implode("\r\n", $headerFields2));
}
发生的事情是 $headerFields"MIME-Version: 1.0", "Content-Type: text/html;charset=utf-8"
为邮件消息设置了 UTF-8。它甚至适用于标题,但需要单独设置为的主题除外:"Subject: =?UTF-8?Q?".imap_8bit($subject)."?=",