jzahedieh
jzahedieh

Reputation: 1579

CakeEmail how to determine failure before stack trace?

I am trying to catch when an email fails so that I can save the required data in my database and I can attempt to send at a later date.

I thought the following should work as it does when using save()

        if ( $email->send() ) {
            //..success - works..
        } else {
            //..fail - never gets here, stack trace
        }

http://i.imgur.com/xY8rq.png

Upvotes: 2

Views: 1000

Answers (1)

mark
mark

Reputation: 21743

obviously you are not in debug mode there. if you were, you would see that this actually throws an exception.

and you are catching sth there, just not the exception thrown :)

try this:

try {
    $success = $email->send();
    ...
} catch (SocketException $e) { // Exception would be too generic, so use SocketException here
    $errorMessage = $e->getMessage();
    ...
}

this way you can catch the exception and do sth here.

Upvotes: 2

Related Questions