$mailer = new sfMailer($dispatcher, array('delivery_strategy' => 'single_address')); $t->fail('__construct() throws an InvalidArgumentException exception if the delivery_address option is not set with the spool single_address strategy'); } catch (InvalidArgumentException $e) { $t->pass('__construct() throws an InvalidArgumentException exception if the delivery_address option is not set with the spool single_address strategy'); } $mailer = new sfMailer($dispatcher, array('delivery_strategy' => 'single_address', 'delivery_address' => '*****@*****.**')); $t->is($mailer->getDeliveryAddress(), '*****@*****.**', '__construct() recognizes the single_address delivery strategy'); // logging $mailer = new sfMailer($dispatcher, array('logging' => false)); $t->is($mailer->getLogger(), null, '__construct() disables logging if the logging option is set to false'); $mailer = new sfMailer($dispatcher, array('logging' => true)); $t->ok($mailer->getLogger() instanceof sfMailerMessageLoggerPlugin, '__construct() enables logging if the logging option is set to true'); // ->compose() $t->diag('->compose()'); $mailer = new sfMailer($dispatcher, array('delivery_strategy' => 'none')); $t->ok($mailer->compose() instanceof Swift_Message, '->compose() returns a Swift_Message instance'); $message = $mailer->compose('*****@*****.**', '*****@*****.**', 'Subject', 'Body'); $t->is($message->getFrom(), array('*****@*****.**' => ''), '->compose() takes the from address as its first argument'); $t->is($message->getTo(), array('*****@*****.**' => ''), '->compose() takes the to address as its second argument'); $t->is($message->getSubject(), 'Subject', '->compose() takes the subject as its third argument'); $t->is($message->getBody(), 'Body', '->compose() takes the body as its fourth argument'); // ->composeAndSend() $t->diag('->composeAndSend()'); $mailer = new sfMailer($dispatcher, array('logging' => true, 'delivery_strategy' => 'none')); $mailer->composeAndSend('*****@*****.**', '*****@*****.**', 'Subject', 'Body'); $t->is($mailer->getLogger()->countMessages(), 1, '->composeAndSend() composes and sends the message'); $messages = $mailer->getLogger()->getMessages(); $t->is($messages[0]->getFrom(), array('*****@*****.**' => ''), '->composeAndSend() takes the from address as its first argument'); $t->is($messages[0]->getTo(), array('*****@*****.**' => ''), '->composeAndSend() takes the to address as its second argument'); $t->is($messages[0]->getSubject(), 'Subject', '->composeAndSend() takes the subject as its third argument'); $t->is($messages[0]->getBody(), 'Body', '->composeAndSend() takes the body as its fourth argument');
static function sendNotificationEmail($name, sfMailer $mailer, aPollPoll $poll, aPollAnswer $answer) { if (!self::getSendNotification($name)) { return false; } sfContext::getInstance()->getConfiguration()->loadHelpers('Partial'); $from = self::isUserOrEmail(self::getNotificationEmailFrom($name), true); $to = self::isUserOrEmail(self::getNotificationEmailTo($name), true); if (is_null($to)) { throw new sfException('No destination email defined. Cannot send a notification.'); } $form_name = aPollToolkit::getPollFormName($poll->getType()); $arguments = array('poll' => $poll, 'poll_form' => new $form_name($answer->getFieldsAsArray()), 'answer' => $answer); $message = $mailer->compose($from, $to); //$message->setContentType("text/html"); $message->setSubject(get_partial(self::getNotificationEmailTitlePartial($name), $arguments)); $body = get_partial(self::getNotificationEmailBodyPartial($name), $arguments); $message->addPart(self::createPlainTextBody($body), 'text/plain'); $message->addPart(self::createHtmlBody($poll->getType(), $body), 'text/html'); $mailer->send($message); return true; }