| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- function mail_template_list()
- {
- static $res;
- if ($res === NULL) {
- $data = read_static_cache('mail_template');
- if ($data == false) {
- $query = $GLOBALS['db']->query('SELECT * FROM `' . $GLOBALS['db_mymps'] . 'mail_template` ORDER BY template_id DESC');
- while ($row = $GLOBALS['db']->fetchRow($query)) {
- $re[$row['template_code']]['template_id'] = $row['template_id'];
- $re[$row['template_code']]['is_sys'] = $row['is_sys'];
- $re[$row['template_code']]['template_code'] = $row['template_code'];
- $re[$row['template_code']]['is_html'] = $row['is_html'];
- $re[$row['template_code']]['template_subject'] = $row['template_subject'];
- $re[$row['template_code']]['template_content'] = $row['template_content'];
- $re[$row['template_code']]['last_modify'] = $row['last_modify'];
- $re[$row['template_code']]['last_send'] = $row['last_send'];
- $re[$row['template_code']]['is_html'] = $row['is_html'];
- $res = $re;
- }
- write_static_cache('mail_template', $res);
- }
- else {
- $res = $data;
- }
- }
- return $res;
- }
- function get_mail_setting()
- {
- global $db;
- global $db_mymps;
- static $res;
- if ($res === NULL) {
- $data = read_static_cache('mail_config');
- if ($data == false) {
- $re = $db->query('SELECT * FROM `' . $db_mymps . 'config` WHERE type=\'mail\'');
- while ($row = $db->fetchRow($re)) {
- $res[$row['description']] = $row['value'];
- }
- write_static_cache('mail_config', $res);
- }
- else {
- $res = $data;
- }
- }
- return $res;
- }
- function write_mail_sendrecord($email_to, $email_subject, $email_content, $error, $template_id)
- {
- global $timestamp;
- $GLOBALS['db']->query('INSERT INTO `' . $GLOBALS['db_mymps'] . 'mail_sendlist` (email,email_subject,email_content,error,last_send,template_id)VALUES(\'' . $email_to . '\',\'' . $email_subject . '\',\'' . $email_content . '\',\'' . $error . '\',\'' . $timestamp . '\',\'' . $template_id . '\')');
- }
- function send_email($email_to, $mail_subject, $mail_body, $mail_type = 'html', $template_id = '')
- {
- $mail_cfg = get_mail_setting();
- if ($mail_cfg['mail_service'] == 'mail') {
- if (@mail($email_to, $mail_subject, $mail_body)) {
- write_mail_sendrecord($email_to, $mail_subject, $mail_body, 0, $template_id);
- return true;
- }
- else {
- write_mail_sendrecord($email_to, $mail_subject, $mail_body, 1, $template_id);
- return false;
- }
- }
- else if ($mail_cfg['mail_service'] == 'smtp') {
- require_once MYMPS_INC . '/email.class.php';
- $smtp = new smtp($mail_cfg['smtp_server'], $mail_cfg['smtp_serverport'], true, $mail_cfg['mail_user'], $mail_cfg['mail_pass']);
- $smtp->debug = false;
- if ($smtp->sendmail($email_to, $mail_cfg['smtp_mail'], $mail_subject, $mail_body, $mail_type)) {
- $error = 0;
- }
- else {
- $error = 1;
- }
- write_mail_sendrecord($email_to, $mail_subject, $mail_body, $error, $template_id);
- return $error == 0 ? true : false;
- }
- else if ($mail_cfg['mail_service'] == 'no') {
- return false;
- }
- }
- function send_pwd_email($uid, $userid, $email, $code, $mobiledomain = '')
- {
- global $db;
- global $db_mymps;
- global $mymps_global;
- global $timestamp;
- $mailtmp = $db->getRow('SELECT * FROM `' . $db_mymps . 'mail_template` WHERE template_id = \'1\'');
- if (empty($mailtmp)) {
- return false;
- }
- else {
- $mail_subject = $mymps_global['SiteName'] . '密码修改';
- if ($mobiledomain) {
- $code = htmlspecialchars_decode($mobiledomain . '/?mod=forgetpass&code=' . $code);
- }
- else {
- $code = htmlspecialchars_decode($mymps_global['SiteUrl'] . '/' . $mymps_global['cfg_member_logfile'] . '?mod=forgetpass&code=' . $code);
- }
- $mail_body = $mailtmp['template_content'];
- $mail_body = str_replace(array('{$user_name}', '{$reset_email}', '{$site_name}', '{$send_date}'), array($userid, $code, $mymps_global['SiteName'], GetTime($timestamp)), $mail_body);
- return send_email($email, $mail_subject, $mail_body, 'html', 1);
- }
- }
- function send_validate_email($uid, $userid, $email, $code)
- {
- global $db;
- global $db_mymps;
- global $mymps_global;
- global $timestamp;
- $mailtmp = $db->getRow('SELECT * FROM `' . $db_mymps . 'mail_template` WHERE template_id = \'2\'');
- if (empty($mailtmp)) {
- return false;
- }
- else {
- $mail_subject = $mymps_global['SiteName'] . '用户验证';
- $code = $mymps_global['SiteUrl'] . '/' . $mymps_global['cfg_member_logfile'] . '?mod=validate&code=' . $code;
- $mail_body = $mailtmp['template_content'];
- $mail_body = str_replace(array('{$user_name}', '{$validate_email}', '{$site_name}', '{$send_date}'), array($userid, $code, $mymps_global['SiteName'], GetTime($timestamp)), $mail_body);
- return send_email($email, $mail_subject, $mail_body, 'html', 1);
- }
- }
- ?>
|