0

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

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 专家查看上面的代码。

任何帮助将不胜感激。

非常感谢。

4

3 回答 3

1

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

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
于 2012-06-23T11:06:34.610 回答
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);
于 2012-06-23T11:12:14.857 回答
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();
于 2012-06-23T11:08:21.153 回答