【问题标题】:How to send HTML email through PHP [duplicate]如何通过 PHP 发送 HTML 电子邮件 [重复]
【发布时间】:2016-01-19 13:10:06
【问题描述】:

我在网上找到了如何执行此操作的说明,但它对我不起作用...我缩短的 PHP 消息是:

$msg = '<html><body>';
$msg .= 'Dear' .$firstname. 'Best wishes';
$msg .= '</body></html>';

我打算在消息中添加一些 html,但这只是出现:

<html><body>
Dear Sam Best wishes
</body></html>

我错过了什么?!谢谢。

【问题讨论】:

  • 检查您的Content-type 标头
  • 好吧,我看你想通了
  • $headers = '内容类型:文本/html;字符集=iso-8859-1' ;添加标题内容类型 = text/html

标签: php html email


【解决方案1】:

请按照official documentation 中添加的说明进行操作。这是一个工作示例,您可以将其与您的代码进行比较。

$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';
$subject = 'Birthday Reminders for August';
$message = '
<html>
<head>
  <title>Birthday Reminders for August</title>
</head>
<body>
  <p>Here are the birthdays upcoming in August!</p>
  <table>
    <tr>
      <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
    </tr>
    <tr>
      <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
    </tr>
    <tr>
      <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
    </tr>
  </table>
</body>
</html>
';
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$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($to, $subject, $message, $headers);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-29
    • 1970-01-01
    • 1970-01-01
    • 2016-05-18
    • 2022-10-23
    • 1970-01-01
    相关资源
    最近更新 更多