* @license PHP License * @package Wombat * @subpackage base */ WBClass::load('WBEvent_Handler'); /** * Event_Handler_Mail * * Send an e-mail... * * @version 0.1.1 * @package Wombat * @subpackage base */ class WBEvent_Handler_Mail extends WBEvent_Handler { /** * Handler config * * Parameters * - "from" e-mail address in from header * - "fromindex" load e-mail address for from header form index * - "rcpt" e-mail address of recipient * - "rcptindex" e-mail address of recipient loaded from index * - "addrcpt" list of additional rcpts * - "lang" locale settings * - "langindex" index for locale settings * - "tmpl" template for mail body * * @var array */ protected $config = array( 'from' => '', 'fromindex' => '', 'rcpt' => '', 'rcptindex' => 'email', 'addrcpt' => '', 'lang' => '', 'langindex' => '', 'tmpl' => 'email' ); /** * send an email * * Use Mailer to prepare and send e-mail. * * @param WBEvent $e * @return bool true to continue, false to stop processing * @throws Exception in case of error */ public function process(WBEvent $e) { // switch to recipient's language first WBClass::load('patI18n'); $lang = patI18n::getLocale(patI18n::LOCALE_TYPE_COMPLETE); if (!empty($this->config['lang'])) { patI18n::setLocale($this->config['lang']); } else if (!empty($this->config['langindex'])) { patI18n::setLocale($e->get($this->config['langindex'], $lang)); } // now as locale settings are settled, start mailer $mailer = WBClass::create('WBMailer'); /** @var $mailer WBMailer */ $mailer->setTemplate($this->config['tmpl']); $mailer->setData($e->get()); $event = array( 'name' => $e->getName(), 'timestamp' => $e->getTimestamp(), 'msg' => $e->getMessage(), 'lang' => patI18n::getLocale(patI18n::LOCALE_TYPE_SHORT) ); $mailer->addData($event, 'event_'); $rcpt = $this->config['rcpt']; if (empty($rcpt) && !empty($this->config['rcptindex'])) { $rcpt = $e->get($this->config['rcptindex']); } if (!empty($rcpt)) { $mailer->addRcpt($rcpt); } // additional RCPT if (!empty($this->config['addrcpt'])) { $mailer->addRcpt($this->config['addrcpt']); } $from = $this->config['from']; if (empty($from) && !empty($this->config['fromindex']) ) { $from = $e->get($this->config['fromindex']); } if (!empty($from)) { $mailer->setFrom($from); } $mailer->send(); // undo changes in locale settings patI18n::setLocale($lang); return true; } } ?>