【问题标题】:PHP mail - special characters don't workPHP 邮件 - 特殊字符不起作用
【发布时间】:2017-04-16 11:45:18
【问题描述】:
<?php
$email = $_POST["email"];
$from = "From: $email \n";
$from .= "Content-type: text/html; charset=UTF-8;";
$to = "MojaFirma@gmail.com";
$title = $_POST["typ"] . " - " . $_POST["name"];
$title = "=?UTF-8?B?" . base64_encode($title) . "?=";
$tel = "";
$tel = $_POST["tel"];
if(empty($tel)) {
    $tel = "";
}
else {
    $tel = "Telefon - " . $tel . '<br/>';
}
$text = '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>';
$text .= $_POST["text"];
$text .= "<br/><br/>".$tel;
$text .= "</body></html>";
mail($to, $title, $text, $from);?>

This is what i get (image)

我添加了 charset=utf-8。我的代码编辑器编码设置为 utf-8。我的标题有特殊字符,但电子邮件正文没有。请帮帮我!

更改后(有效):

<?php
$email = $_POST["email"];
$from = "MIME-Version: 1.0" . "\r\n";
$from .= "Content-Type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: base64\r\n";
$from .= "From: $email" . "\r\n";
$to = "MojaFirma@gmail.com";
$title = $_POST["typ"] . " - " . $_POST["name"];
$title = "=?UTF-8?B?" . base64_encode($title) . "?=";
$tel = "";
$tel = $_POST["tel"];
if(empty($tel)) {
    $tel = "";
}
else {
    $tel = "Telefon - " . $tel . '<br/>';
}
$text = '<html><head><meta charset="utf-8"></head><body>';
$text .= $_POST["text"];
$text .= "<br/><br/>".$tel;
$text .= "</body></html>";
$text = base64_encode($text);
echo $text;
mail($to, $title, $text, $from);?>

【问题讨论】:

  • 这是基于 $_POST["text"] 的值。你可以var_dump($_POST["text"]);然后分享输出。
  • 我做到了,得到了这个:string(158) "ąężźćśó Telefon - 123 123 123" 所以这是正确的,但电子邮件的正文不是......
  • 尝试将您的文本编码为quoted-printablebase64
  • "Content-Type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: base64\r\n"
  • 哦,是的!谢谢,成功了!

标签: php email


【解决方案1】:

正如Deadooshkaits comment 中所指出的,您必须更改行

$from .= "Content-type: text/html; charset=UTF-8;";

$from .= "Content-Type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: base64\r\n";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-11
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    相关资源
    最近更新 更多