CakePHP电子邮件组件检查电子邮件是否发送 [英] CakePHP Email Component check if email was sent

查看:174
本文介绍了CakePHP电子邮件组件检查电子邮件是否发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道如何在CakePHP中使用EmailComponent时检查电子邮件是发送还是失败?

I am just wondering how can you check if email was sent or it failed whenever using the EmailComponent in CakePHP?

例如,我目前以这种方式使用它: / p>

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();


推荐答案

$ this->如果发送成功,则发送邮件 - > send() 应该返回true。您可以尝试以下方式:

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

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

参考:

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

注意:如果您使用的是CakePHP 2.x,可以尝试使用CakeEmail上课EmailComponent已被弃用(参考资料)。如果你使用1.x然后继续。 :p

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

编辑:

如评论中所述, em>使用2.x你应该记住,CakeEmail(由EmailComponent使用)可以引发异常。您可以使用 CakePHP本身或通过投掷一个try / catch来处理它:

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
}

这篇关于CakePHP电子邮件组件检查电子邮件是否发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆