为什么收件人没有收到我使用 PHP 发送的 HTML 格式(仅文本)的电子邮件


Why a recipient does not receive an email in HTML format (only text) that I send using PHP?

无论我做什么,无论我阐述什么标题,它都不起作用。甚至我也在标题中插入了内容类型(在消息本身内)。我会发疯的...

PHP 版本:5.2.17

机器: Linux

内核版本:2.6.32-46.1.BHsmp(如果这很重要)

<?php
$headers = "From: <sender@mydomain.com>" . "'n";
$headers .= "MIME-Version: 1.0" . "'n";
$headers .= "http-equiv='Content-Type' content='text/html; charset=iso-8859-1''r'n";
$emailBody="<html>";
$emailBody .= "<head>";
$emailBody .= "<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>";
$emailBody .= "</head>";
$emailBody .= "<body>";
$emailBody .= "Hello Dear, <br><b>Bla Bla</b><br> See you later. <br>Bye.";
$emailBody .= "</body>";
$emailBody .= "</head>";
$emailBody .= "</html>";
mail("<recipient@gmail.com>", "Testing some HTML mail", $emailBody, $headers);
?>

等待 PHP/HTML 专家查看上面的代码。

任何帮助将不胜感激。

多谢。

这将简单地工作..

$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';
// subject
$subject = 'Birthday Reminders for August';

$message = '
<html>
<head>
  <title>Birthday Reminders ...';

$headers  = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "'r'n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "'r'n";
$headers .= 'Cc: birthdayarchive@example.com' . "'r'n";
$headers .= 'Bcc: birthdaycheck@example.com' . "'r'n";
// Mail it
mail($to, $subject, $message, $headers);

尝试以这种格式设置标题:

$headers  = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";

如果你愿意使用像PHPMailer这样的库,它使发送HTML消息变得更加容易。您不必担心边界字符串、标头等。

下面是一些示例代码:

$mailer = new PHPMailer();
$mailer->IsHTML(true);
$mailer->ContentType = 'text/html';
$mailer->FromName = $from;
$mailer->Subject = $subject;
$mailer->Body = $yourHtmlContent;
$mailer->AddAddress($someRecipientAddress);
$mailer->Send();