Symfony 任务邮件
我使用 symfony 1.4.11 ,我需要从任务中发送邮件。我使用 这篇文章。所以我有下一个简单的代码,例如:
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',)
但是这些字母没有发送到我的电子邮件...也许我的代码不正确?
I use symfony 1.4.11 , And I need to make mailing from task. I use this article. So I have next simple code for example:
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);
}
}
So task work without error, I have :
>> 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',)
but the letters do not com to my email...Maybe I have incorrect code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看这篇文章:http://www.symfony.com symfony-project.org/more-with-symfony/1_4/en/04-Emails#chapter_04_configuration
也许你已经设置在您的
dev
或test
环境中,将delivery_strategy
更改为none
。Check out this article: http://www.symfony-project.org/more-with-symfony/1_4/en/04-Emails#chapter_04_configuration
Maybe you have set
delivery_strategy
tonone
in yourdev
ortest
environment.