Gmailアカウントを持つ単純なメールアプリケーションをhost.Itとして開発していますが、send()関数が例外をスローすると問題が発生します。 try catchステートメントが例外を処理できないことがわかりました。 グローバル例外クラスを使用しても動作しません。 この質問はどこかでも議論されています。例えばSwiftmailerの例外がSymfony2コントローラでキャッチしない
:
Catch swiftmailer exception in Symfony2 dev env controller
または
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('[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'));
}
私は放火魔コンソールで受信コードの上から送信された応答は次のとおりです。
{"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を持っている(つまりものの問題・オブコースです) 私は\Exception
にException
を変更したり、 \Swift_TransportException
またはさらにSwift_TransportException
!良い結果は得られません。
'Swift_SwiftException'を試しましたか?このファイルには、 "Base Exception class"と書かれています。 – ferdynator
"Base Exception class"で "Exception"を意味する – CoderInNetwork
"Swift_SwiftException"と "\ Swift_SwiftException"でテストしました。動作しません。 – CoderInNetwork