質問

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('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);     
}

}

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top