php 发送邮件函数的示例支持html和普通文本

感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。
经测试代码如下:

<?PHP
/**
 * 发送邮件
 *
 * @param 
 * @arrange (编程之家) jb51.cc
 **/
function send_mail($emailaddress,$fromaddress,$namefrom,$emailsubject,$body)
{
$eol=\n;
$mime_boundary=md5(time());

# Common Headers
$headers .= From: $namefrom <$fromaddress>.$eol;
$headers .= Reply-To: $namefrom <$fromaddress>.$eol;
$headers .= Return-Path: $namefrom <$fromaddress>.$eol;
// these two to set reply address
$headers .= Message-ID: <.$Now. TheSystem@.$_SERVER['SERVER_NAME'].>.$eol;
$headers .= X-Mailer: PHP v.PHPversion().$eol; // These two to help avoid spam-filters

# Boundry for marking the split & Multitype Headers
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= Content-Type: multipart/related; boundary=\.$mime_boundary.\.$eol;

$msg = ;

# Setup for text OR html
$msg .= Content-Type: multipart/alternative.$eol;

# Text Version
$msg .= --.$mime_boundary.$eol;
$msg .= Content-Type: text/plain; charset=iso-8859-1.$eol;
$msg .= Content-transfer-encoding: 8bit.$eol;
$msg .= strip_tags(str_replace(<br>,\n,$body)).$eol.$eol;

# HTML Version
$msg .= --.$mime_boundary.$eol;
$msg .= Content-Type: text/html; charset=iso-8859-1.$eol;
$msg .= Content-transfer-encoding: 8bit.$eol;
$msg .= $body.$eol.$eol;

# Finished
$msg .= --.$mime_boundary.--.$eol.$eol; // finish with two eol's for better security. see Injection.

# SEND THE EMAIL
// ini_set(sendmail_from,$fromaddress); // the INI lines are to force the From Address to be used !
mail($emailaddress,$msg,$headers);

// ini_restore(sendmail_from);
// echo mail send;
return 1;
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...