misc_sendmail.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: misc_sendmail.php 30849 2012-06-26 02:21:32Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. header('Content-Type: text/javascript');
  12. $pernum = 1;
  13. dsetcookie('sendmail', '1', 300);
  14. $lockfile = DISCUZ_ROOT.'./data/sendmail.lock';
  15. @$filemtime = filemtime($lockfile);
  16. if($_G['timestamp'] - $filemtime < 5) exit();
  17. touch($lockfile);
  18. @set_time_limit(0);
  19. $list = $sublist = $cids = $touids = array();
  20. foreach(C::t('common_mailcron')->fetch_all_by_sendtime($_G['timestamp'], 0, $pernum) as $value) {
  21. if($value['touid']) $touids[$value['touid']] = $value['touid'];
  22. $cids[] = $value['cid'];
  23. $list[$value['cid']] = $value;
  24. }
  25. if(empty($cids)) exit();
  26. foreach(C::t('common_mailqueue')->fetch_all_by_cid($cids) as $value) {
  27. $sublist[$value['cid']][] = $value;
  28. }
  29. if($touids) {
  30. C::t('common_member_status')->update($touids, array('lastsendmail' => TIMESTAMP), 'UNBUFFERED');
  31. }
  32. C::t('common_mailcron')->delete($cids);
  33. C::t('common_mailqueue')->delete_by_cid($cids);
  34. require_once libfile('function/mail');
  35. foreach ($list as $cid => $value) {
  36. $mlist = $sublist[$cid];
  37. if($value['email'] && $mlist) {
  38. $subject = getstr($mlist[0]['subject'], 80, 0, 0, 0, -1);
  39. $message = '';
  40. if(count($mlist) == 1) {
  41. $message = '<br>'.$mlist[0]['message'];
  42. } else {
  43. foreach ($mlist as $subvalue) {
  44. if($subvalue['message']) {
  45. $message .= "<br><strong>$subvalue[subject]</strong><br>$subvalue[message]<br>";
  46. } else {
  47. $message .= $subvalue['subject'].'<br>';
  48. }
  49. }
  50. }
  51. if(!sendmail($value['email'], $subject, $message)) {
  52. runlog('sendmail', "$value[email] sendmail failed.");
  53. }
  54. }
  55. }
  56. ?>