I am developing a web applicationen on base of the silex framework with decent Mail functionality. Sending mails works fine with the basic configuration and established connection to the mail server. In the case of errors e.g. due to connection loss, i want to log the causes and prevent them to be sent to the client. But iam unable to catch the mailer errors, especially the Swift_TransportException. I encapsulated the call of the 'send' function and also added an Error handler, both without success. Is this a bug, or am i missing something?
The error handler:
$app->error(function (\Swift_TransportException $e, Request $request, $code) {
//TODO log
});
The usage of the send function:
try{
$message = \Swift_Message::newInstance()
->setSubject($mail->getSubject())
->setFrom($mail->getFrom())
->setTo($mail->getTo())
->setBody($mail->getBody());
$app['mailer']->send($message);
}
catch(\Swift_TransportException $exception)
{
//TODO log
}