Created
September 10, 2013 18:36
-
-
Save phpfour/6513636 to your computer and use it in GitHub Desktop.
Debugging email sending issue with SwiftMailer in Symfony2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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('[email protected]') | |
->setTo('[email protected]') | |
->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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would add echo $mailLogger->dump(); to get log content.