Symfony 任务邮件

发布于 2024-11-28 15:14:12 字数 2490 浏览 2 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半寸时光 2024-12-05 15:14:12

查看这篇文章:http://www.symfony.com symfony-project.org/more-with-symfony/1_4/en/04-Emails#chapter_04_configuration

也许你已经设置在您的 devtest 环境中,将 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 to none in your dev or test environment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文