Skip to content

Instantly share code, notes, and snippets.

@phpfour
Created September 10, 2013 18:36
Show Gist options
  • Save phpfour/6513636 to your computer and use it in GitHub Desktop.
Save phpfour/6513636 to your computer and use it in GitHub Desktop.
Debugging email sending issue with SwiftMailer in Symfony2.
<?php
namespace Rbs\Bundle\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class EmailController extends Controller
{
public function testAction()
{
$mailLogger = new \Swift_Plugins_Loggers_ArrayLogger();
$this->mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($mailLogger));
$message = \Swift_Message::newInstance()
->setSubject('Hello')
->setFrom('phpfour@gmail.com')
->setTo('apu.eee@gmail.com')
->setBody('This is a test email.');
if ($this->mailer->send($message)) {
echo '[SWIFTMAILER] sent email to ' . $toEmail;
} else {
echo '[SWIFTMAILER] not sending email: ' . $mailLogger->dump();
}
}
}
@jflefebvre
Copy link

I would add echo $mailLogger->dump(); to get log content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment