I am developing a simple mailing application with Gmail account as host.It works like a charm but the problem rises when send() function throw an exception. I see that try catch statement can't handle the exception. It doesn't work even when I use Global exception class. this question discussed in somewhere also .
for example :
Catch swiftmailer exception in Symfony2 dev env controller
or
https://groups.google.com/forum/#!topic/symfony2/SlEzg_PKwJw
but they didn't reach a working answer.
My controller function code is :
public function ajaxRegisterPublisherAction()
{
//some irrelevant logic
$returns= json_encode(array("username"=>$username,"responseCode"=>$responseCode));
try{
$message = \Swift_Message::newInstance()
->setSubject('hello world')
->setFrom('[email protected]')
->setTo('[email protected]')
->setBody(
$this->renderView('AcmeSinamelkBundle:Default:email.txt.twig',array('name'=>$username,"password"=>$password))
);
$this->container->get("mailer")->send($message);
}
catch (Exception $e)
{
}
return new \Symfony\Component\HttpFoundation\Response($returns,200,array('Content-Type'=>'application/json'));
}
The response that sent from above code that I receive in firebug console is :
{"username":"xzdvxvvcvxcv","responseCode":200}<!DOCTYPE html>
<html>
.
.
Swift_TransportException: Connection could not be established with host smtp.gmail.com [Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?]
.
.
</html>
and I catch my hairs because I don't know why the kernel handle the exception in continue of my json object?
when I comment this line:
$this->container->get("mailer")->send($message);
the exception doesn't occur and I have a valid json in client side.(that is matter-of- course although)
I changed Exception
to \Exception
or \Swift_TransportException
or even Swift_TransportException
! but no good result.
Swift_SwiftException
? In the file it says "Base Exception class." – Gal