【发布时间】:2013-03-05 22:24:54
【问题描述】:
如何在使用 php mail() 函数发送的电子邮件中输出主题中断 (
)。在电子邮件中,它显示为
本身,而不是主题休息。
【问题讨论】:
-
你说单杠'
-
您需要设置标题以说出其html电子邮件,并包含适当的html,manual中的示例4
-
以 HTML 格式而不是纯文本格式发送您的电子邮件。
如何在使用 php mail() 函数发送的电子邮件中输出主题中断 (
【问题讨论】:
查看示例 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);
?>
【讨论】:
如果您想在使用 mail() 发送的电子邮件中使用 HTML,则必须添加一个 Content-type 标头以声明该电子邮件应被解析为 HTML。请参阅http://php.net/manual/en/function.mail.php的示例 4
【讨论】: