PHP邮件()不显示HTML

问题描述:

我们最近升级到了Plesk并行Linux服务器,看起来好像PHP设置忽略了标题!电子邮件收到罚款,但显示 HTML标记。PHP邮件()不显示HTML

phpInfo()文件可以在这里看到:https://www.pressgofer.com/phpInfo.php

的PHP本身应该没问题,但反正这里包括它。

PHP代码的邮件

$email = "[email protected]"; 
$message = "<h1 style='font-family:Helvetica,Arial;font-size:17px'>Your account has a password reset request</h1>"; 

$headers = "From: [email protected] \r\n"; 
$headers .= "Reply-To: [email protected] \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); 

非常感谢, 尼克

+0

在消息前尝试'mime'和'content-type'。 – 2013-03-21 10:47:08

+2

您的phpinfo显示mail.add_x_header已关闭。你需要打开它。 – 2013-03-21 10:48:14

+0

@Renku不会有任何区别 - 两个变量同时传递到mail()函数中。不过谢谢。 – 2013-03-21 10:48:36

phpinfo表明mail.add_x_header关闭。你需要把它

要启用X-Mail头,在你的php.ini

<?php 
$to = "[email protected]"; 
$subject = "My HTML email test."; 
$headers = "From: [email protected]\r\n"; 
$headers .= "Reply-To: [email protected]\r\n"; 
$headers .= "Return-Path: [email protected]\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!"; 
    } 
?> 
+0

非常感谢。现在就试试这个。 – 2013-03-21 10:50:26

+0

@Nick价格:我的荣幸 – 2013-03-21 10:50:56

+0

是的,有可能是php.ini文件的权限问题。尝试复制文件到您的桌面,然后访问它搜索术语“mail.add_x_header” – 2013-03-21 10:53:30

sending mail from php: headers are interpreted as body?

问题是MIME类型和服务器interpretation-没有\r需要相关的设置mail.add_x_header为1。