我们最近升级到了 Plesk 并行 Linux 服务器,PHP 设置似乎忽略了 header !电子邮件接收正常,但显示 HTML 标记。
可以在此处查看 phpInfo()
文件:https://www.pressgofer.com/phpInfo.php
PHP 本身应该没问题,但无论如何都将其包含在此处。
PHP 邮件代码
$email = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a6bba2aeb3afa683a6bba2aeb3afa6eda0acae" rel="noreferrer noopener nofollow">[email protected]</a>";
$message = "<h1 style='font-family:Helvetica,Arial;font-size:17px'>Your account has a password reset request</h1>";
$headers = "From: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b7574697e6b77625b6b697e68687c747d7e6935787476" rel="noreferrer noopener nofollow">[email protected]</a> \r\n";
$headers .= "Reply-To: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e789889582978b9ea797958294948088818295c984888a" rel="noreferrer noopener nofollow">[email protected]</a> \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($email, "Reset password notification", $message, $headers);
非常感谢, 尼克
最佳答案
您的phpinfo
显示mail.add_x_header
已关闭。你需要打开它
要启用 X-Mail
header ,请在 php.ini
中将 mail.add_x_header
设置为 1
<?php
$to = "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f68f998384869a979593b685999b93819e938493d895999b" rel="noreferrer noopener nofollow">[email protected]</a>";
$subject = "My HTML email test.";
$headers = "From: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="89fae0e7e1e8a7e2fae8fcfbe8ebe1c9eee4e8e0e5a7eae6e4" rel="noreferrer noopener nofollow">[email protected]</a>\r\n";
$headers .= "Reply-To: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="43302a2d2b226d283022363122212b03242e222a2f6d202c2e" rel="noreferrer noopener nofollow">[email protected]</a>\r\n";
$headers .= "Return-Path: <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa899394929bd491899b8f889b9892ba9d979b9396d4999597" rel="noreferrer noopener nofollow">[email protected]</a>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= "<h1> This is a test </h1>";
$message .= "</body></html>";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
关于PHP mail() 不显示 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15545206/