Symfony2 + swift mailer +命令:显示在控制台中的电子邮件正文

Sam*_*Sam 3 swiftmailer symfony

我已经在我的Symfony应用程序中创建了一个新命令.

在此命令中,我调用一个服务,该服务从FOS包发送邮件 作为邮件程序.

我的问题是电子邮件正文显示在控制台中以发送电子邮件.

我想说的是,该msg mailer方法工作正常进行的命令.

这是我的命令:

class ReminderCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->container = $this->getApplication()->getKernel()->getContainer();            

        # the mailer service works fine out the command
        $mailer = $this->container->get('mailer');
        $mailer->sendMsg(...);          


        $text = ' => mail sent';

        $output->writeln($text);
    }
}
Run Code Online (Sandbox Code Playgroud)

请帮忙

谢谢

山姆

小智 16

我想你可能已经使用了内存假脱机.

使用内存假脱机时,您必须注意,由于symfony处理控制台命令的方式,因此不会自动发送电子邮件.你必须自己清理队列.使用以下代码在console命令中发送电子邮件:

$container = $this->getContainer();
$mailer = $container->get('mailer');
$spool = $mailer->getTransport()->getSpool();
$transport = $container->get('swiftmailer.transport.real');
$spool->flushQueue($transport);
Run Code Online (Sandbox Code Playgroud)

参考:http: //symfony.com/doc/2.0/cookbook/console/sending_emails.html

  • 这应该是公认的答案,谢谢! (2认同)