php 发送html格式邮件的简单示例

前端之家收集整理的这篇文章主要介绍了php 发送html格式邮件的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:

<?PHP
/**
 * 发送html格式邮件
 *
 * @param 
 * @arrange (512.笔记) jb51.cc
 **/
function htmlmail($to,$subject,$message,$headers = NULL)
{
$mime_boundary = md5(time());

$headers .= "\nMessage-ID: <" . time() . " TheSystem@{$_SERVER['SERVER_NAME']}>\n";
$headers .= "X-Mailer: PHP " . PHPversion() . "\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative;boundary={$mime_boundary}\n\n";

$newmessage = "This is a multi-part message in MIME format.";
$newmessage .= "\n\n--{$mime_boundary}\n";
$newmessage .= "Content-type: text/plain;charset=utf-8\n\n";
$newmessage .= strip_tags(str_replace(array('<br>','<br />'),"\n",$message)) . "\n\n";

$newmessage .= "\n\n--{$mime_boundary}\n";
$newmessage .= "Content-type: text/html;charset=utf-8\n\n";

// prepended HTML
$newmessage .= '<body style="margin:0"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td bgcolor="#ffffff" valign="top"><table width="750" border="0" cellpadding="0" cellspacing="0" align="center"><tr><td bgcolor="#ffffff" width="750">';

// HTML message that was passed to this function
$newmessage .= $message;

// appended HTML
$newmessage .= '</td></tr></table></td></tr></table></body>';

return mail($to,$newmessage,$headers);
}


/*** 来自:编程之家 jb51.cc(jb51.cc) ***/ 

猜你在找的PHP相关文章