我只是想知道如何在CakePHP中使用EmailComponent时检查电子邮件是否已发送或失败?
例如,我目前以这种方式使用它:
$this->Email->from='<xyz@yahoo.com>';
$this->Email->to='<abc@gmail.com>';
$this->Email->sendAs='both';
$this->Email->delivery = 'debug';
$this->Email->send();
Run Code Online (Sandbox Code Playgroud)
Big*_*gel 10
$this->Email->send() 如果成功发送,则应返回true.你可以尝试类似的东西:
if ( $this->Email->send() ) {
// Success
} else {
// Failure
}
Run Code Online (Sandbox Code Playgroud)
参考:
http://api.cakephp.org/2.3/class-EmailComponent.html
注意:如果您正在使用CakePHP 2.x,您可以尝试使用CakeEmail类; 不推荐使用EmailComponent(参考).如果你使用1.x然后继续.:p
编辑:
正如在评论中指出,如果你正在使用2.x的,你应该记住,CakeEmail(这是使用EmailComponent)可引发异常.您可以使用CakePHP本身或通过尝试/捕获来处理它:
try {
if ( $this->Email->send() ) {
// Success
} else {
// Failure, without any exceptions
}
} catch ( Exception $e ) {
// Failure, with exception
}
Run Code Online (Sandbox Code Playgroud)