按:把下面的代码拷贝到<body></body>之间,把邮箱名更换一下,即可执行。
<?php
//定义邮件发往的邮箱
$to = 'to@example.com';
//定义邮件标题
$subject = 'TXT/HTML Email';
//创建一个唯一的 a boundary string。
$rm_hash = md5(time()); //你可以用其他方法创建这个唯一的字符串
//定义发送邮件的邮箱,它将作为发件箱显示在收件箱里,并用\r\n换行
$headers = "From: from@example.com\r\n";
//添加格式
$headers .= "Content-Type: multipart/alternative; boundary=\"PHP-alt-".$rm_hash."\"";
//下面是邮件内容
ob_start(); //打开缓冲区
?>
--PHP-alt-<?php echo $rm_hash; ?>
Content-Type: text/plain; charset="utf-8"
http://www.coolder.com/1028-1-1
您收到这封信,因为您订阅了这个主题,您可以登录这个主题,修改您的帖子的属性,取消订阅。
You're getting this mail because you subscribed to the topic, visit the topic and login to unsubscribe.
--PHP-alt-<?php echo $rm_hash; ?>
Content-Type: text/html; charset="utf-8"
<br>
<a href="http://www.coolder.com/1028-1-1">用mail()发送TXT/HTML格式的邮件(附代码)</a>
<br>您收到这封信,因为您订阅了这个主题,您可以登录这个主题,修改您的帖子的属性,取消订阅。
<br>You're getting this mail because you subscribed to the topic, visit the topic and login to unsubscribe.
--PHP-alt-<?php echo $rm_hash; ?>--
<?php
//将目前缓冲区的内容拷贝到$message里
$message = ob_get_clean();
//发送邮件
$send_mail = @mail( $to, $subject, $message, $headers);
//根据返回信息,显示邮件发送是否成功
echo $send_mail ? "Email发送成功" : "Email发送失败";
?>