龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php发送html邮件

时间:2014-06-19 15:11来源:网络整理 作者:网络 点击:
分享到:
php发送html邮件 发邮件方法定义:```{php}function htmlmail($to, $subject, $message, $headers = NULL){$mime_boundary = md5(time()); $headers .= quot;\nMessage-ID: lt;quot; . time() . quot; TheSystem@{$_SERVER[#39;SERVER_NAME#39;]

发邮件方法定义:

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, $subject, $newmessage, $headers);
}

使用方法:

EXAMPLE: htmlmail('user@domain.com', 'Look ma, HTML e-mails','You just got <a href="http://www.yougotrickrolled.com/">Rick Rolled</a>');
NOTE: $headers is optional, but can be used to set From, CC, etc. Go to http://www.htmlite.com/php029.php for info
精彩图集

赞助商链接