email.fun.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. function mail_template_list()
  3. {
  4. static $res;
  5. if ($res === NULL) {
  6. $data = read_static_cache('mail_template');
  7. if ($data == false) {
  8. $query = $GLOBALS['db']->query('SELECT * FROM `' . $GLOBALS['db_mymps'] . 'mail_template` ORDER BY template_id DESC');
  9. while ($row = $GLOBALS['db']->fetchRow($query)) {
  10. $re[$row['template_code']]['template_id'] = $row['template_id'];
  11. $re[$row['template_code']]['is_sys'] = $row['is_sys'];
  12. $re[$row['template_code']]['template_code'] = $row['template_code'];
  13. $re[$row['template_code']]['is_html'] = $row['is_html'];
  14. $re[$row['template_code']]['template_subject'] = $row['template_subject'];
  15. $re[$row['template_code']]['template_content'] = $row['template_content'];
  16. $re[$row['template_code']]['last_modify'] = $row['last_modify'];
  17. $re[$row['template_code']]['last_send'] = $row['last_send'];
  18. $re[$row['template_code']]['is_html'] = $row['is_html'];
  19. $res = $re;
  20. }
  21. write_static_cache('mail_template', $res);
  22. }
  23. else {
  24. $res = $data;
  25. }
  26. }
  27. return $res;
  28. }
  29. function get_mail_setting()
  30. {
  31. global $db;
  32. global $db_mymps;
  33. static $res;
  34. if ($res === NULL) {
  35. $data = read_static_cache('mail_config');
  36. if ($data == false) {
  37. $re = $db->query('SELECT * FROM `' . $db_mymps . 'config` WHERE type=\'mail\'');
  38. while ($row = $db->fetchRow($re)) {
  39. $res[$row['description']] = $row['value'];
  40. }
  41. write_static_cache('mail_config', $res);
  42. }
  43. else {
  44. $res = $data;
  45. }
  46. }
  47. return $res;
  48. }
  49. function write_mail_sendrecord($email_to, $email_subject, $email_content, $error, $template_id)
  50. {
  51. global $timestamp;
  52. $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 . '\')');
  53. }
  54. function send_email($email_to, $mail_subject, $mail_body, $mail_type = 'html', $template_id = '')
  55. {
  56. $mail_cfg = get_mail_setting();
  57. if ($mail_cfg['mail_service'] == 'mail') {
  58. if (@mail($email_to, $mail_subject, $mail_body)) {
  59. write_mail_sendrecord($email_to, $mail_subject, $mail_body, 0, $template_id);
  60. return true;
  61. }
  62. else {
  63. write_mail_sendrecord($email_to, $mail_subject, $mail_body, 1, $template_id);
  64. return false;
  65. }
  66. }
  67. else if ($mail_cfg['mail_service'] == 'smtp') {
  68. require_once MYMPS_INC . '/email.class.php';
  69. $smtp = new smtp($mail_cfg['smtp_server'], $mail_cfg['smtp_serverport'], true, $mail_cfg['mail_user'], $mail_cfg['mail_pass']);
  70. $smtp->debug = false;
  71. if ($smtp->sendmail($email_to, $mail_cfg['smtp_mail'], $mail_subject, $mail_body, $mail_type)) {
  72. $error = 0;
  73. }
  74. else {
  75. $error = 1;
  76. }
  77. write_mail_sendrecord($email_to, $mail_subject, $mail_body, $error, $template_id);
  78. return $error == 0 ? true : false;
  79. }
  80. else if ($mail_cfg['mail_service'] == 'no') {
  81. return false;
  82. }
  83. }
  84. function send_pwd_email($uid, $userid, $email, $code, $mobiledomain = '')
  85. {
  86. global $db;
  87. global $db_mymps;
  88. global $mymps_global;
  89. global $timestamp;
  90. $mailtmp = $db->getRow('SELECT * FROM `' . $db_mymps . 'mail_template` WHERE template_id = \'1\'');
  91. if (empty($mailtmp)) {
  92. return false;
  93. }
  94. else {
  95. $mail_subject = $mymps_global['SiteName'] . '密码修改';
  96. if ($mobiledomain) {
  97. $code = htmlspecialchars_decode($mobiledomain . '/?mod=forgetpass&code=' . $code);
  98. }
  99. else {
  100. $code = htmlspecialchars_decode($mymps_global['SiteUrl'] . '/' . $mymps_global['cfg_member_logfile'] . '?mod=forgetpass&code=' . $code);
  101. }
  102. $mail_body = $mailtmp['template_content'];
  103. $mail_body = str_replace(array('{$user_name}', '{$reset_email}', '{$site_name}', '{$send_date}'), array($userid, $code, $mymps_global['SiteName'], GetTime($timestamp)), $mail_body);
  104. return send_email($email, $mail_subject, $mail_body, 'html', 1);
  105. }
  106. }
  107. function send_validate_email($uid, $userid, $email, $code)
  108. {
  109. global $db;
  110. global $db_mymps;
  111. global $mymps_global;
  112. global $timestamp;
  113. $mailtmp = $db->getRow('SELECT * FROM `' . $db_mymps . 'mail_template` WHERE template_id = \'2\'');
  114. if (empty($mailtmp)) {
  115. return false;
  116. }
  117. else {
  118. $mail_subject = $mymps_global['SiteName'] . '用户验证';
  119. $code = $mymps_global['SiteUrl'] . '/' . $mymps_global['cfg_member_logfile'] . '?mod=validate&code=' . $code;
  120. $mail_body = $mailtmp['template_content'];
  121. $mail_body = str_replace(array('{$user_name}', '{$validate_email}', '{$site_name}', '{$send_date}'), array($userid, $code, $mymps_global['SiteName'], GetTime($timestamp)), $mail_body);
  122. return send_email($email, $mail_subject, $mail_body, 'html', 1);
  123. }
  124. }
  125. ?>