【发布时间】:2013-04-02 15:45:26
【问题描述】:
如何检查在 CakePHP 中发送电子邮件是否成功?
我可以发送电子邮件没问题,但如果发送失败,我希望能够处理错误。我怎样才能做到这一点?
这是我到目前为止所做的:
$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);
【问题讨论】:
-
你使用 try catch 了吗?
-
充其量您可以检测到邮件是否已正确传递到 smtp 服务器。您无法直接检测接收服务器是否拒绝/发送垃圾邮件,或者您的 smtp 服务器是否延迟/排队邮件。
标签: php email cakephp error-handling