无法使用RabbitMQ和Symfony2发送Swift_Message

时间:2012-11-10 12:24:19

标签: php symfony rabbitmq swiftmailer

我正在使用RabbitMQBundle将RabbitMQ集成到我的symfony2项目中。一切正常(我可以制作和使用消息)。但是,每当我尝试使用来自消费者的Swift_Message发送电子邮件时,我都不会收到该电子邮件。使用来自消费者的mail('foo@bar.com', 'subject', 'message');确实有效。

这是我用来发送Swift_Message的代码:

 $message = \Swift_Message::newInstance()
    ->setSubject($subject)
    ->setFrom('noreply@bar.com')
    ->setTo('foo@bar.com')
    ->setBody('Foo Bar');

  $this->container->get('mailer')->send($message);

此代码在“普通”控制器或服务中运行。但是,当RabbitMQ在消费者中触发时,它不起作用。

有任何线索吗?

1 个答案:

答案 0 :(得分:9)

您应该禁用swiftmailer的假脱机功能:删除swiftmailer捆绑包配置的spool

来自

swiftmailer:
    # ...
    spool: { type: memory }

swiftmailer:
    # ...

您可以阅读有关此功能的更多信息here