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

时间:2012-06-23 11:01:30

标签: php html email

无论我做什么,无论我详细说明什么标题,它都行不通。 甚至我在标题中插入了内容类型(在消息本身内)。我会发疯的......

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专家审核上述代码。

任何帮助都将受到高度赞赏。

非常感谢。

3 个答案:

答案 0 :(得分:1)

请尝试以此格式设置标题:

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

答案 1 :(得分:1)

这将简单地工作..

$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);

答案 2 :(得分:0)

如果您愿意使用像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();