0
我使用symfony 1.4.11,并且我需要从任务发送邮件。我使用this文章。所以,我对于接下来例如简单的代码:Symfony任务邮寄
class mailerSendTask extends sfBaseTask
{
protected function configure()
{
$this->addOptions(array(
new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name','frontend'),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'doctrine'),
// add your own options here
));
$this->namespace = 'mailer';
$this->name = 'send';
$this->briefDescription = 'Ads mailling';
$this->detailedDescription = <<<EOF
The [mailer:send|INFO]
Mailing links to new ads for all users who are subscribed.
Call it with:
[php symfony mailer:send|INFO]
EOF;
}
protected function execute($arguments = array(), $options = array())
{
// initialize the database connection
$databaseManager = new sfDatabaseManager($this->configuration);
$connection = $databaseManager->getDatabase($options['connection'])->getConnection();
$context = sfContext::createInstance($this->configuration);
$this->configuration->loadHelpers('Partial');
$message = $this->getMailer()->compose('[email protected]', 'mymailgmail.com', 'New Ads');
// generate HTML part
$context->getRequest()->setRequestFormat('html');
$html ='some text';// get_partial('ads/mailing',array ('user_id'=>$user_id));
$message->setBody($html, 'text/html');
// send the message
$this->getMailer()->sendNextImmediately()->send($message);
}
}
所以任务的工作无差错,我有:
>> sfPatternRouting Connect sfRoute "sf_guard_signin" (/login)
>> sfPatternRouting Connect sfRoute "sf_guard_signout" (/logout)
>> sfPatternRouting Connect sfRoute "sf_guard_password" (/request_password)
>> sfPatternRouting Match route "homepage" (/) for/with parameters array ( 'module' => 'main', 'action' => 'index',)
但信件没有COM到我的邮箱......也许我有不正确的代码?
默认情况下,他在开发中运行它,默认策略没有。他应该在产品环境中运行它。 – Maerlyn
我很蠢。是的,我在** delivery_strategy ** dev中没有策略。我的任务在开发中运行。 – denys281