加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php 发送邮件函数功能实例

发布时间:2020-05-30 21:39:16 所属栏目:PHP 来源:互联网
导读:php 发送邮件函数功能实例

对php发送邮件函数感兴趣的小伙伴,下面一起跟随脚本之家 jb51.cc的小编两巴掌来看看吧!


/**
 * php发送邮件函数
 *
 * @param 
 * @arrange 网: jb51.cc
 **/
function sendEmail($to,$from,$subject,$message,$html_message=null) {
$eol = "n";
$mime_boundary = md5(time());   
$mime_boundary_header = chr(34) . $mime_boundary . chr(34);
if (empty($html_message)) {
$html_message = nl2br($message);
}
$headers = "From: $from" . $eol;
$headers .= "Message-ID: <" . time() . " domain>" . $eol;
$headers .= "X-Mailer: PHP v" . phpversion() . $eol;          // These two to help avoid spam-filters
$headers .= 'MIME-Version: 1.0' . $eol;
// Setup for text OR html
$headers .= "Content-Type: multipart/alternative; boundary=" . 
$mime_boundary_header . $eol . $eol;
$msg = "This is a multi-part message in MIME format to $to." . 
$eol . $eol;
// Text Version
$msg .= "--" . $mime_boundary . $eol;
$msg .= "Content-Type: text/plain;" .$eol . $eol;
//$msg .= "Content-Transfer-Encoding: base64".$eol;
//$msg .= base64_encode($txt_body).$eol.$eol;
$msg .= $message . $eol . $eol;
// HTML Version
$msg .= "--".$mime_boundary . $eol;
$msg .= "Content-Type: text/html;{$eol}Content-Transfer-Encoding: 7bit" . 
$eol . $eol;
//$msg .= "Content-Transfer-Encoding: base64".$eol;
//$msg .= base64_encode($html_body).$eol.$eol;
$msg .= $html_message . $eol . $eol;
// finish with two eol's for better security. see Injection.
$msg .= "--" . $mime_boundary . "--" . $eol . $eol;
if (isset($_SERVER) && isset($_SERVER['HTTP_HOST']) && !preg_match('/.com$/',$_SERVER['HTTP_HOST'])) {
// DEV
preg_match('/[w|d| |-]+/',$subject_label);
if (defined('DOCUMENT_ROOT')) {
$logfile = DOCUMENT_ROOT .'/scripts/logs/sendEmail/mail_'. microtime(true);
} else {
$logfile = '../../scripts/logs/sendEmail/mail_'. microtime(true);
}
if (isset($subject_label[0])) {
$logfile .= ' - '. $subject_label[0];
}
$fh = fopen($logfile . '.log','w+');
if (!$fh) {
$fh = fopen(preg_replace('/^..//','',$logfile) . '.log','w+');
}
if ($fh) {
$filelog_content = date('Y-m-d H:i:s')."nn";
$filelog_content .= print_r($to,true)."n";
$filelog_content .= print_r($subject,true)."nn";
$filelog_content .= print_r($msg,true);
fwrite($fh,$filelog_content);
fclose($fh);
}
} else {
mail($to,$msg,$headers,"-fdonotreply@domain.com");
}
}
/***   来自脚本之家 jb51.cc(jb51.cc)   ***/

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读