使用 PHP mail() 寄送HTML格式電子郵件範例

PHP 元件是本公司 Windows / Linux 系列伺服器支援的程式語言之一,以下簡單介紹以HTML格式寄信的程式碼,利用該程式即可有效的寄出多變化的信件:

phpmailhtml.html ( 寄送 HTML 格式的電子郵件 ) :2003.2.24 更新

<?php

/* 收件人 */
$to = "Kelly <kelly@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>
';

/* To send HTML mail, you can set the Content-type header. */
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=big5\r\n";

/* additional headers */
$headers .= "From: Birthday Reminder <birthday@example.com>\r\n";

$headers .= "Cc: birthdayarchive@example.com\r\n";
$headers .= "Bcc: birthdaycheck@example.com\r\n";

/* and now mail it */
mail($to, $subject, $message, $headers);

?>



上面使用 PHP mail() 寄出 HTML 格式的電子郵件只是一個簡單的範例,您可以依您的需要做適當的修改;您也可以參考原廠網站以進一步了解更多的功能。