Swiftmailer说DoctrineDataCollector :: serialize()必须返回一个字符串或NULL

时间:2014-02-14 22:48:40

标签: symfony swiftmailer mailer

我已经设置了Swiftmailer用于Symfony2,下面的代码在我尝试过的第一个控制器中工作正常。

    $message = \Swift_Message::newInstance()
    ->setSubject('sent from coupon admin')
    ->setFrom( array($this->container->getParameter('outgoing_address')=>'Admin'))
    ->setTo($user->getEmail())
    ->setBody('X');

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

但当我把它移到第二个时,我实际上需要它才能工作,它会抛出三个例外:

3/3    Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector::serialize() must return a string or NULL

2/3    Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector::serialize() must return a string or NULL

1/3    Serialization of 'SimpleXMLElement' is not allowed

当我用get('mailer')移除最后一行时,第二个控制器工作正常,所以它肯定是邮件相关的,我只是无法弄清楚为什么第一个没有尝试序列化Swiftmailer消息但是第二个是然后失败了。如果这有所不同的话,我现在在开发模式下查看它。

1 个答案:

答案 0 :(得分:0)

事实证明我的问题是我设置的emil主题实际上是SimpleXMLElement而不是字符串。当处于开发模式时,它会尝试记录所有内容,而在prod模式下则不会,因此它永远不会发生错误。