/** * 发送邮件 * * @param array $params */ public function sendEmail($params) { if (empty($params['emails']) || empty($params['content']) || empty($params['subject']) || empty($params['url']) || empty($params['sender']) || empty($params['type']) || empty($params['lastupdate']) || empty($params['tuduid'])) { return; } $tpl = $this->_options['data']['path'] . '/templates/tudu/rule_mail_notify.tpl'; if (!file_exists($tpl) || !is_readable($tpl)) { $this->getLogger()->warn("Tpl file:\"rule_mail_notify.tpl\" is not exists"); return; } $tuduId = $params['tuduid']; $emails = $params['emails']; $common = $params; unset($common['emails']); unset($common['tuduid']); $mailTransport = $this->getMailTransport($this->_balancer->select()); $template = $this->_assignTpl(file_get_contents($tpl), $common); foreach ($emails as $email) { try { $mail = new Zend_Mail('utf-8'); $mail->setFrom($this->_options['smtp']['from']['alert'], urldecode($this->_options['smtp']['fromname'])); $mail->addTo($email); $mail->addHeader('tid', $tuduId); $mail->setSubject("邮件主题:" . $params['subject']); $mail->setBodyHtml($template); $mail->send($mailTransport); } catch (Zend_Mail_Exception $ex) { $this->getLogger()->warn("[Failed] Send rule email notify TuduId:{$tuduId} retry\n{$ex}"); continue; } } $this->getLogger()->debug("Send rule email notify id:{$tuduId} done"); }
/** * 重写父类方法 * * @param string $idx * @return Oray_Balancer_Rotation */ public function setCurrent($idx) { parent::setCurrent($idx); $item = reset($this->_items); do { if (key($this->_items) === $idx) { break; } } while (false !== ($item = next($this->_items))); return $this; }