mail.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /**
  3. * 任务计划 - 邮件发动送
  4. *
  5. * 建议10分钟触发一次
  6. *
  7. *
  8. */
  9. defined('InShopNC') or exit('Access Invalid!');
  10. class mailControl {
  11. private $_num = 50; // 每次发送消息数量
  12. /**
  13. * 初始化对象
  14. */
  15. public function __construct(){
  16. register_shutdown_function(array($this,"shutdown"));
  17. }
  18. /**
  19. * 发送消息
  20. */
  21. public function indexOp() {
  22. $model_storemsgcron = Model('mail_cron');
  23. $cron_array = $model_storemsgcron->getMailCronList(array(), $this->_num);
  24. if (!empty($cron_array)) {
  25. $email = new Email();
  26. $mail_array = array();
  27. foreach ($cron_array as $val) {
  28. $return = $email->send_sys_email($val['mail'],$val['subject'],$val['contnet']);
  29. if ($return) {
  30. // 记录需要删除的id
  31. $mail_array[] = $val['mail_id'];
  32. }
  33. }
  34. // 删除已发送的记录
  35. $model_storemsgcron->delMailCron(array('mail_id' => array('in', $mail_array)));
  36. }
  37. }
  38. /**
  39. * 执行完成提示信息
  40. *
  41. */
  42. public function shutdown(){
  43. exit("success at ".date('Y-m-d H:i:s',time())."\n");
  44. }
  45. }