Can anyone tell me how to catch this exception and gracefully handle it? I'm trying to create a sort of spooler daemon and don't want the script to die.
Fatal error: Uncaught exception 'Swift_BadResponseException' with message 'Expec
ted response code(s) [250] but got response []' in C:\Program Files\Apache Group
\Apache2\htdocs\cap\trunk\app\vendors\Swift.php:250
Stack trace:
#0 C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\vendors\Swift.php(
310): Swift->assertCorrectResponse(Object(Swift_Events_ResponseEvent), 250)
#1 C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\vendors\Swift.php(
262): Swift->command('HELO localhost....', 250)
#2 C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\vendors\Swift.php(
220): Swift->handshake(Object(Swift_Events_ResponseEvent))
#3 C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\vendors\Swift.php(
101): Swift->connect()
#4 C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\email_spooler.php(
48): Swift->__construct(Object(Swift_Connection_SMTP))
#5 {main}
thrown in C:\Program Files\Apache Group\Apache2\htdocs\cap\trunk\app\vendors\S
wift.php on line 250
Catching/handling exceptions Swift_BadResponseException
Moderators: Chris Corbyn, General Moderators
-
EricWinchell
- Forum Newbie
- Posts: 5
- Joined: Tue Aug 28, 2007 2:27 pm
-
EricWinchell
- Forum Newbie
- Posts: 5
- Joined: Tue Aug 28, 2007 2:27 pm
I suppose the exception just needs to be caught, like this?
Code: Select all
try {
$swift->send( ... );
} catch (Exception $e) {
do_something_with_failed($recipient);
$swift->reset();
}- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
The exception isn't being thrown during the send(), it's being thrown during the "new Swift(...)" call. You need to use a try/catch yesEricWinchell wrote:I suppose the exception just needs to be caught, like this?
Code: Select all
try { $swift->send( ... ); } catch (Exception $e) { do_something_with_failed($recipient); $swift->reset(); }
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
PHP4 is being dropped in February, because it's a pain to deal with, but basically you need to use set_error_handler() to catch the errors and deal with them. There is a Swift_Error::expect() workaround but I've not had a massive amount of success with it unless you know the implementation (i.e. it works for me, but does unexpected things for others).snursita wrote:I also have the same problem, and unfortunately I use PHP4. How can I catch the exception? Sorry I never emulate a try catch in PHP4 before.
If you can upgrade to PHP5, or push your host to upgrade then do that, otherwise jusy use set_error_handler().
http://www.swiftmailer.org/gophp5/