Check if successful / unsuccessful email sending in CakePHP?

How to check if email was sent successfully in CakePHP?

I can send letters without problems, but I want to be able to handle this error if it is not sent. How can i do this?

This is what I have done so far:

$email = new CakeEmail();
$email->from(array('email' => 'title'));
$email->to($to);
$email->subject('Account activation');     
$activate_url = 'http://' . env('SERVER_NAME') .'/cakephp/users/activate/'.$id.'/'.$token;
$message = "Thank you for signing up. Click on the activation link to activate your account \n";
return $email->send($message.$activate_url);
+5
source share
1 answer

You can use the catch try block to check if the mail was successfully forwarded by the MTA, you cannot really detect or check if the mail was successfully delivered to the recipient. This is a different case.

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

, , , , .

+9

All Articles