Codeigniter 电子邮件错误处理
CI Email send() 函数只返回 true 或 false.有没有办法获得发送失败的更详细原因?我正在使用 SMTP.
The CI Email send() function only returns true or false. Is there a way to get a more detailed reason as to why a sending failed? I'm using SMTP.
推荐答案
您可以使用电子邮件调试器进一步检查发生的情况:
You can further inspect what happened by using the email debugger:
$r = $this->send(FALSE);
if (!$r)
$this->email->print_debugger()
;
来自 Codeigniter 电子邮件类参考.
如果您需要将调试器输出为字符串,您可以使用 输出缓冲区:
If you need the debugger output as a string, you can just catch the output with an output buffer:
$errors = array();
... # Loop
$r = $this->send(FALSE);
if (!$r) {
ob_start();
$this->email->print_debugger();
$error = ob_end_clean();
$errors[] = $error;
}
... # Loop end
最新版本中的 Codeigniter 需要为 提供明确的 FALSE
参数,以便不清除消息和调试,如果传递失败有效地杀死调试器函数错误.email->send()
函数的$auto_clear
Codeigniter in more recent versions requires an explicit FALSE for the $auto_clear
parameter of the email->send()
function in order to not clear the message and the debugging, effectively killing the debugger function if you fail to pass the FALSE.
相关文章