public function send(Mail $mail) { if (self::$available) { if ($this->queued) { // 如果是发送到列队,则将邮件插入到邮件列队表 $mail->save(); return true; } else { $ul = ucfirst(self::$available); $class = "\\Helper\\Mailer\\{$ul}"; $mailer = new $class(); $result = $mailer->send($mail); if ($result) { return true; } return false; } } else { throw new Error("Mail Exception: CLASS " . self::$available . " not available"); } return false; }
public function run() { if (!Option::get('mail_queue')) { return; } Logger::getInstance()->info('mail queue running..'); $mailer = Mailer::getInstance(); $mailer->toQueue(false, true); // set to queue. $mailQueue = MMail::getQueueList(); if (count($mailQueue) > 0) { foreach ($mailQueue as $mail) { $mail->delete(); $mail->content = htmlspecialchars_decode($mail->content); Logger::getInstance()->info('send mail to ' . $mail->to); $mailer->send($mail); } } else { Option::set('mail_queue', 0); } }