gpt4 book ai didi

php - 将 Unicode UTF8 添加到电子邮件

转载 作者:搜寻专家 更新时间:2023-10-31 20:41:59 25 4
gpt4 key购买 nike

谁能帮助我如何为这些字符添加 utf-8 Unicode?

žýáťčšľľzŽŘ

现在邮件看起来像这样

Dostali ste novú správu. Tu sú podrobnosti: Jméno: tár Tel.Äíslo: 4996611

<?php

$EmailFrom = "...";
$EmailTo = "mail@mail";
$Subject = "Zpráva s ";
$name = Trim(stripslashes($_POST['name']));
$phone = Trim(stripslashes($_POST['phone']));
$email = Trim(stripslashes($_POST['email']));
$message = Trim(stripslashes($_POST['message']));

// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";

// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

谢谢

最佳答案

您的脚本有两个不明确的部分,其中没有考虑字符集。可能您的表单未发送 UTF-8,或者您可能在电子邮件中发送 UTF-8,但客户期望使用不同的编码。

  1. 我假设您正在使用表单发布数据。确保它设置为从浏览器发送 UTF-8。字符串现在将采用 UTF-8 编码。

    <form action="myform" accept-charset="UTF-8">
  2. 您需要将字符集和传输编码 header 添加到电子邮件 header :

    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>\r\nContent-Type: text/plain; charset=UTF-8\r\nContent-Transfer-Encoding: 8bit");

顺便说一句,重定向用户的更快方法是在响应中设置 Location header 。使用:

header('Location: contactthanks.php')

关于php - 将 Unicode UTF8 添加到电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19997052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com