【问题标题】:Output <hr> in email message php在电子邮件 php 中输出 <hr>
【发布时间】:2013-03-05 22:24:54
【问题描述】:

如何在使用 php mail() 函数发送的电子邮件中输出主题中断 (


)。在电子邮件中,它显示为
本身,而不是主题休息。

【问题讨论】:

  • 你说单杠'
  • 您需要设置标题以说出其html电子邮件,并包含适当的html,manual中的示例4
  • 以 HTML 格式而不是纯文本格式发送您的电子邮件。

标签: php html email


【解决方案1】:

查看示例 4:

http://php.net/manual/en/function.mail.php

<?php
// multiple recipients
$to  = 'aidan@example.com' . ', '; // note the comma
$to .= 'wez@example.com';

// subject
$subject = 'Birthday Reminders for August';

// message
$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>
';

// To send HTML mail, the Content-type header must be set
$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】:

如果您想在使用 mail() 发送的电子邮件中使用 HTML,则必须添加一个 Content-type 标头以声明该电子邮件应被解析为 HTML。请参阅http://php.net/manual/en/function.mail.php的示例 4

【讨论】:

    猜你喜欢
    • 2012-10-04
    • 2012-04-29
    • 1970-01-01
    • 1970-01-01
    • 2014-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-17
    相关资源
    最近更新 更多