PHP邮件-特殊字符不起作用
我添加了charset=utf-8。我的代码编辑器编码设置为utf-8。我的标题有特殊字符,但电子邮件正文中没有。请帮帮我 更改后,它可以工作:PHP邮件-特殊字符不起作用,php,email,Php,Email,我添加了charset=utf-8。我的代码编辑器编码设置为utf-8。我的标题有特殊字符,但电子邮件正文中没有。请帮帮我 更改后,它可以工作: <?php $email = $_POST["email"]; $from = "From: $email \n"; $from .= "Content-type: text/html; charset=UTF-8;"; $to = "MojaFirma@gmail.com"; $title = $_POST["typ"] . " - " . $
<?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);?>
如中所述,您必须更改行
<?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);?>
到
这是基于$u POST[text]的值。您可以使用var_dump$_POST[text];然后分享输出。我这样做了,得到了:string158ąężźćśóTelefon-123,所以这是对的,但电子邮件正文不是…。尝试将文本编码为引用的可打印文本或base64。内容类型:text/html;charset=utf-8\r\n内容传输编码:base64\r\nOhh yees!!谢谢你,这很有效!
$from .= "Content-type: text/html; charset=UTF-8;";
$from .= "Content-Type: text/html; charset=utf-8\r\nContent-Transfer-Encoding: base64\r\n";