如何在 PHP 中使用标准邮件功能发送 HTML 格式的消息

How to send HTML-formatted message with standard mail function in PHP

我正在尝试在我的联系我们表单中使用以下内容来接收来自我的访问者的格式良好的 html 电子邮件:

$message .='<table width="800" border="0" cellspacing="3" cellpadding="3" style="margin-bottom: 20px">';
$message .='<caption style="text-align:left;background:#eee;padding:5px;font-size:18px;font-weight:bold;">Webmail</caption>';
$message .='<tr><td width="200"><strong>Date</strong></td><td width="600" style="border:1px solid #ccc;">'.$todayis.'</td></tr>';
$message .='<tr><td width="200"><strong>From</strong></td><td width="600" style="border:1px solid #ccc;">'.$name.'</td></tr>';
$message .='<tr><td width="200"><strong>Email</strong></td><td width="600" style="border:1px solid #ccc;">'.$email.'</td></tr>';
$message .='<tr><td width="200"><strong>Subject</strong></td><td width="600" style="border:1px solid #ccc;">'.$recipient.'</td></tr>';
$message .='</table>';
$message .= '<div style="width:770px;background:#eee;padding:15px;">';
$message .= '<div style="font-weight: bold; font-size: 18px;padding-bottom: 10px;">Your Message</div>';
$message .= $message;
$message .= '</div>';
$message .='<table width="800" border="0" cellspacing="3" cellpadding="3" style="margin-bottom: 20px">';
$message .='<caption style="text-align:left;background:#eee;padding:5px;font-size:18px;font-weight:bold;">Webmail Data</caption>';
$message .='<tr><td width="200"><strong>IP Address</strong></td><td width="600" style="border:1px solid #ccc;">'.$ip.'</td></tr>';
$message .='<tr><td width="200"><strong>Browser Info</strong></td><td width="600" style="border:1px solid #ccc;">'.$httpagent.'</td></tr>';
$message .='<tr><td width="200"><strong>Referral</strong></td><td width="600" style="border:1px solid #ccc;">'.$httpref.'</td></tr>';
$message .='</table>';

$headers = "From: " . $email . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "X-Priority: 1\r\n";
$sent = mail($to, $subject, $message, $headers);

我遇到的问题是,当我使用 text/html 时,电子邮件显示为已发送,但我没有收到,当我将其更改为 text/plain 时,一切正常,除了我收到了所有内容在没有任何 HTML 格式的纯文本中。

我在自己专用的 Apache 服务器上,运行 Plesk 12.0.18 和 CentOS6.6 我需要在服务器上配置什么吗?我已尝试将电子邮件配置为以 HTML 格式接收所有内容,但似乎没有用。

感谢任何帮助。

Php Html 电子邮件

<?php
$to = "abc@gmail.com";
$subject = "PUT_SUBJECT_HERE";
$mail_body = '<html>
<body bgcolor="#573A28" topmargin="25">
Put HTML content here with variables from PHP if you like
Variable display Example: ' . $subject . ' 
<h1>this is a heading</h1>
</body>
</html>';
//$headers  = "From: abc@gmail.com";
//$headers .= "Content-type: text/html";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <abc@gmail.com>' . "\r\n";
mail($to, $subject, $mail_body, $headers);
?>

享受这个代码