/** * Factory method for creating an email log writer based on the configuration array * @param array $config * @return \Zend\Log\Writer\Mail */ public function create($config) { $to = $config['to']; $from = $config['from']; $subject = $config['subject']; //create the message object that should be sent $message = new \Zend\Mail\Message(); //populate it with data based on the config $message->setFrom($from); $message->setSubject($subject); if (is_string($to)) { $to = array($to); } foreach ($to as $email) { $message->addTo($email); } //create the log writer $writer = new Mail($message); //set up a formatter if present if (isset($config['formatter'])) { $formatter = new $config['formatter'](); $writer->setFormatter($formatter); } return $writer; }
/** * @return Mail */ protected function _getMailWriter() { $oMailMessage = new MailMessage(); if (isset($this->_aConfig['writer']['mail']['sender_mail']) && isset($this->_aConfig['writer']['mail']['sender_name'])) { $oMailMessage->setFrom($this->_aConfig['writer']['mail']['sender_mail'], $this->_aConfig['writer']['mail']['sender_name']); } foreach ((array) $this->_aConfig['writer']['mail']['receivers'] as $sRec) { $oMailMessage->addTo($sRec); } $oWriter = new Mail($oMailMessage, $this->_oTransportService->getTransport()); $oWriter->setFormatter($this->_getDefaultFormatter()); if (isset($this->_aConfig['writer']['mail']['subject_prepend_text'])) { $oWriter->setSubjectPrependText($this->_aConfig['writer']['mail']['subject_prepend_text']); } $oFilter = new FilterPriority(Logger::ERR); $oWriter->addFilter($oFilter); return $oWriter; }