ホストとしてGmailアカウントを使用して単純なメールアプリケーションを開発しています.それは魅力のように機能しますが、send()関数が例外をスローすると問題が発生します. try catch ステートメントでは例外を処理できないことがわかりました。グローバル例外クラスを使用しても機能しません。この質問はどこかでも議論されています。
例えば :
Symfony2 dev 環境コントローラーで swiftmailer 例外をキャッチする
また
https://groups.google.com/forum/#!topic/symfony2/SlEzg_PKwJw
しかし、彼らは有効な答えに達しませんでした。
私のコントローラー機能コードは次のとおりです。
public function ajaxRegisterPublisherAction()
{
//some irrelevant logic
$returns= json_encode(array("username"=>$username,"responseCode"=>$responseCode));
try{
$message = \Swift_Message::newInstance()
->setSubject('hello world')
->setFrom('jafarzadeh91@gmail.com')
->setTo('jafarzadeh991@yahoo.com')
->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'));
}
上記のコードから送信され、firebug コンソールで受信した応答は次のとおりです。
{"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>
カーネルがjsonオブジェクトの継続で例外を処理する理由がわからないため、髪をキャッチしますか?
この行にコメントすると:
$this->container->get("mailer")->send($message);
例外は発生せず、クライアント側に有効な json があります (当然のことですが) or or even !に変更Exception
しました。しかし、良い結果はありません。\Exception
\Swift_TransportException
Swift_TransportException