本文整理汇总了PHP中sfMailer::compose方法的典型用法代码示例。如果您正苦于以下问题:PHP sfMailer::compose方法的具体用法?PHP sfMailer::compose怎么用?PHP sfMailer::compose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfMailer
的用法示例。
在下文中一共展示了sfMailer::compose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sfMailer
$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' => 'foo@example.com'));
$t->is($mailer->getDeliveryAddress(), 'foo@example.com', '__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('from@example.com', 'to@example.com', 'Subject', 'Body');
$t->is($message->getFrom(), array('from@example.com' => ''), '->compose() takes the from address as its first argument');
$t->is($message->getTo(), array('to@example.com' => ''), '->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('from@example.com', 'to@example.com', 'Subject', 'Body');
$t->is($mailer->getLogger()->countMessages(), 1, '->composeAndSend() composes and sends the message');
$messages = $mailer->getLogger()->getMessages();
$t->is($messages[0]->getFrom(), array('from@example.com' => ''), '->composeAndSend() takes the from address as its first argument');
$t->is($messages[0]->getTo(), array('to@example.com' => ''), '->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');
示例2: sendNotificationEmail
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;
}