繁体   English   中英

PHP邮件-特殊字符不起作用

[英]PHP mail - special characters don't work

<?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);?>

这就是我得到的(图片)

我添加了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);?>

Deadooshka其评论中所述 ,您必须更改行

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM