Рассылка задач Symfony - PullRequest
       21

Рассылка задач Symfony

0 голосов
/ 10 августа 2011

Я использую 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('no-reply@some.com', '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',)

, но письма не приходят на мою электронную почту ...есть неверный код?

1 Ответ

3 голосов
/ 10 августа 2011

Ознакомьтесь с этой статьей: http://www.symfony -project.org / more-with-symfony / 1_4 / ru / 04-Emails # chapter_04_configuration

Возможно, вы установили delivery_strategy на none в вашей dev или test среде.

...