Question

I have set up Swiftmailer for use in Symfony2 and the code below works fine in the first controller I tried it in.

    $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);

But when I moved it to a second one, where I actually need it to work it throws three exceptions:

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

When I remove the last line with get('mailer') the second controller works fine, so it is definitely mailer related, I just can't work out why the first one isn't trying to serialize the Swiftmailer message but the second one is and then fails so hard. I've viewing this in dev mode at the moment if that makes a difference.

Was it helpful?

Solution

It turns out my problem was that the emil subject I was setting was actually a SimpleXMLElement rather than a string. And when in dev mode it tries to log everything, whilst in prod mode it doesn't so it never hit that error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top