CakePHP Email Component check if email was sent

cakephp, email

Solution

`$this->Email->send()` should return true if it was sent successfully. You could try something like:

if ( $this->Email->send() ) {
    // Success
} else {
    // Failure
}

Reference:

http://api.cakephp.org/2.3/class-EmailComponent.html

Note: If you're using CakePHP 2.x you might try using the CakeEmail class instead; EmailComponent is deprecated (Reference). If you're using 1.x then carry on. :p

Edit:

As noted in the comments, if you are using 2.x you should keep in mind that CakeEmail (which is used by EmailComponent) can throw an exception. You can handle it with CakePHP itself or by tossing in a try/catch:

try {
    if ( $this->Email->send() ) {
        // Success
    } else {
        // Failure, without any exceptions
    }
} catch ( Exception $e ) {
    // Failure, with exception
}

Problem

I am just wondering how can you check if email was sent or it failed whenever using the EmailComponent in CakePHP? For example I currently use it this way: ``` $this->Email->from='<xyz@yahoo.com>'; $this->Email->to='<abc@gmail.com>'; $this->Email->sendAs='both'; $this->Email->delivery = 'debug'; $this->Email->send(); ```

Original source