<?php 


/** 
***************************************************
*欢迎使用免费版SiteTeam企业建站软件！
*这是一个专业为搜索引擎营销而设计的，极稳定、极易维护的建站软件！
*官方客服：help@php.net.cn
*官方下载网址：http://www.SiteTeam.cn 
***************************************************
**/




 require_once SITE_ROOT . '/include/class.phpmailer.php'; require_once SITE_ROOT . '/include/class.smtp.php'; if (!defined('EMAIL_SYSTEM_DEBUG')) define('EMAIL_SYSTEM_DEBUG','0'); if (!defined('EMAIL_ATTACHMENTS_ENABLED')) define('EMAIL_ATTACHMENTS_ENABLED', true); if (!defined('EMAIL_ATTACH_EMBEDDED_IMAGES')) define('EMAIL_ATTACH_EMBEDDED_IMAGES', 'Yes'); if (!defined('SMTPAUTH_EMAIL_PROTOCOL')) define('SMTPAUTH_EMAIL_PROTOCOL', 'none'); define('EMAIL_TRANSPORT', ($_Mail_Conf['mailsend'] == 1) ? 'smtpauth' : 'PHP'); define('EMAIL_SMTPAUTH_MAIL_SERVER', $_Mail_Conf['server']); define('EMAIL_SMTPAUTH_MAIL_SERVER_PORT', $_Mail_Conf['port']); define('EMAIL_SMTPAUTH_MAILBOX', $_Mail_Conf['auth_username']); define('EMAIL_SMTPAUTH_PASSWORD', $_Mail_Conf['auth_password']); define('EMAIL_CHARSET', $_Mail_Conf['charset']); define('EMAIL_FROM', $_Mail_Conf['auth_username']); define('EMAIL_SEND_MUST_BE', (isset($_Mail_Conf['must_be']) && $_Mail_Conf['must_be'] == '0' ? 'No' : 'Yes')); define('EMAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -t -i'); define('EMAIL_USE_HTML', 'false'); define("EMAIL_LINEFEED", ""); function send_mail($to_name, $to_address, $email_subject, $email_text, $from_email_name, $from_email_address, $attachments_list='' ) { global $newAttachmentsList; foreach(array($from_email_address, $to_address, $from_email_name, $to_name, $email_subject) as $key=>$value) { if (preg_match("/\r/i",$value) || preg_match("/\n/i",$value)) return false; } if (trim($email_text) == '') return false; if (preg_match("/ *([^<]*) *<([^>]*)> */i",$from_email_address,$regs)) { $from_email_name = trim($regs[1]); $from_email_address = $regs[2]; } if ($from_email_name == $from_email_address) $from_email_name = 'SiteTeam'; foreach(explode(',',$to_address) as $key=>$value) { if (preg_match("/ *([^<]*) *<([^>]*)> */i",$value,$regs)) { $to_name = str_replace('"', '', trim($regs[1])); $to_email_address = $regs[2]; } elseif (preg_match("/ *([^ ]*) */i",$value,$regs)) { $to_email_address = trim($regs[1]); } if (!isset($to_email_address)) $to_email_address = trim($to_address); while (strstr($email_text, '&amp;&amp;')) $email_text = str_replace('&amp;&amp;', '&amp;', $email_text); while (strstr($email_text, '&amp;')) $email_text = str_replace('&amp;', '&', $email_text); while (strstr($email_text, '&&')) $email_text = str_replace('&&', '&', $email_text); while (strstr($email_text, '&quot;')) $email_text = str_replace('&quot;', '"', $email_text); while (strstr($email_text, chr(0))) $email_text = str_replace(chr(0), ' ', $email_text); $text = strip_tags($email_text); $email_html = stripslashes($email_text); $mail = new PHPMailer(); $mail->PluginDir = "./include/"; $mail->SetLanguage("en", 'include/support/'); $mail->CharSet = EMAIL_CHARSET; $mail->Encoding = '7bit'; if ((int)EMAIL_SYSTEM_DEBUG > 0 ) $mail->SMTPDebug = (int)EMAIL_SYSTEM_DEBUG; $mail->WordWrap = 76; $mail->LE = (EMAIL_LINEFEED == 'CRLF') ? "\r\n" : "\n"; switch (EMAIL_TRANSPORT) { case 'smtp': $mail->IsSMTP(); $mail->Host = trim(EMAIL_SMTPAUTH_MAIL_SERVER); if (EMAIL_SMTPAUTH_MAIL_SERVER_PORT != '25' && EMAIL_SMTPAUTH_MAIL_SERVER_PORT != '') $mail->Port = trim(EMAIL_SMTPAUTH_MAIL_SERVER_PORT); $mail->LE = "\r\n"; break; case 'smtpauth': $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->Username = defined('EMAIL_SMTPAUTH_MAILBOX') ? trim(EMAIL_SMTPAUTH_MAILBOX) : EMAIL_FROM; $mail->Password = trim(EMAIL_SMTPAUTH_PASSWORD); $mail->Host = trim(EMAIL_SMTPAUTH_MAIL_SERVER); if (EMAIL_SMTPAUTH_MAIL_SERVER_PORT != '25' && EMAIL_SMTPAUTH_MAIL_SERVER_PORT != '') $mail->Port = trim(EMAIL_SMTPAUTH_MAIL_SERVER_PORT); $mail->LE = "\r\n"; if (EMAIL_SMTPAUTH_MAIL_SERVER_PORT == '465' || EMAIL_SMTPAUTH_MAIL_SERVER_PORT == '587' || EMAIL_SMTPAUTH_MAIL_SERVER == 'smtp.gmail.com') $mail->Protocol = 'ssl'; if (defined('SMTPAUTH_EMAIL_PROTOCOL') && SMTPAUTH_EMAIL_PROTOCOL != 'none') { $mail->Protocol = SMTPAUTH_EMAIL_PROTOCOL; if (SMTPAUTH_EMAIL_PROTOCOL == 'starttls' && defined('SMTPAUTH_EMAIL_CERTIFICATE_CONTEXT')) { $mail->Starttls = true; $mail->Context = SMTPAUTH_EMAIL_CERTIFICATE_CONTEXT; } } break; case 'PHP': $mail->IsMail(); break; case 'Qmail': $mail->IsQmail(); break; case 'sendmail': case 'sendmail-f': $mail->LE = "\n"; default: $mail->IsSendmail(); if (defined('EMAIL_SENDMAIL_PATH')) $mail->Sendmail = trim(EMAIL_SENDMAIL_PATH); break; } $mail->Subject = $email_subject; $mail->From = $from_email_address; $mail->FromName = $from_email_name; $mail->AddAddress($to_email_address, $to_name); if (EMAIL_SEND_MUST_BE=='Yes') $mail->From = EMAIL_FROM; if (EMAIL_TRANSPORT=='sendmail-f' || EMAIL_SEND_MUST_BE=='Yes') { $mail->Sender = EMAIL_FROM; } if (EMAIL_USE_HTML == 'true') $email_html = processEmbeddedImages($email_html, $mail); if ($attachments_list == '') $attachments_list = array(); if (is_string($attachments_list)) { if (file_exists($attachments_list)) { $attachments_list = array(array('file' => $attachments_list)); } else { $attachments_list = array(); } } if (isset($newAttachmentsList) && is_array($newAttachmentsList)) $attachments_list = $newAttachmentsList; if (defined('EMAIL_ATTACHMENTS_ENABLED') && EMAIL_ATTACHMENTS_ENABLED && is_array($attachments_list) && sizeof($attachments_list) > 0) { foreach($attachments_list as $key => $val) { $fname = (isset($val['name']) ? $val['name'] : null); $mimeType = (isset($val['mime_type']) && $val['mime_type'] != '' && $val['mime_type'] != 'application/octet-stream') ? $val['mime_type'] : ''; switch (true) { case (isset($val['raw_data']) && $val['raw_data'] != ''): $fdata = $val['raw_data']; if ($mimeType != '') { $mail->AddStringAttachment($fdata, $fname, "base64", $mimeType); } else { $mail->AddStringAttachment($fdata, $fname); } break; case (isset($val['file']) && file_exists($val['file'])): $fdata = $val['file']; if ($mimeType != '') { $mail->AddAttachment($fdata, $fname, "base64", $mimeType); } else { $mail->AddAttachment($fdata, $fname); } break; } } } if (EMAIL_USE_HTML == 'true' && trim($email_html) != '') { $mail->IsHTML(true); $mail->Body = $email_html; $mail->AltBody = $text; } else { $mail->Body = $text; } if (!($result = $mail->Send())) { } } return true; } function processEmbeddedImages ($email_html, & $mail) { if (defined('EMAIL_ATTACH_EMBEDDED_IMAGES') && EMAIL_ATTACH_EMBEDDED_IMAGES == 'Yes') { $imageFiles = array(); $imagesToProcess = array(); if (preg_match_all('#<img.*src=\"(.*?)\".*?\/>#', $email_html, $imagesToProcess)) { for ($i = 0, $n = count($imagesToProcess[0]); $i < $n; $i ++) { $exists = strpos($imagesToProcess[0][$i], 'embed="yes"'); if ($exists !== false) { if (array_key_exists($imagesToProcess[1][$i], $imageFiles)) { $substitute = $imageFiles[$imagesToProcess[1][$i]]; } elseif (file_exists(DIR_FS_CATALOG . $imagesToProcess[1][$i])) { $rpos = strrpos($imagesToProcess[1][$i], '.'); $ext = substr($imagesToProcess[1][$i], $rpos + 1); $name = basename($imagesToProcess[1][$i], '.'.$ext); switch (strtolower($ext)) { case 'gif': $mimetype = 'image/gif'; break; case 'jpg': case 'jpeg': $mimetype = 'image/jpeg'; break; case 'png': default: $mimetype = 'image/png'; break; } $substitute = $name . $i; $mail->AddEmbeddedImage(DIR_FS_CATALOG . $imagesToProcess[1][$i], $substitute, $name . '.' . $ext, "base64", $mimetype); $imageFiles[$imagesToProcess[1][$i]] = $substitute; } $email_html = str_replace($imagesToProcess[1][$i], 'cid:'.$substitute, $email_html); } } } } return $email_html; } ?>