我想知道如何在Codeigniter实际发送之前捕获电子邮件类错误。
例如,如果函数找不到附件,则似乎没有在框架内引发错误(至少我可以确定)。
$this->email->attach('/path/to/file.ext');
我试过了:
if( !$this->email->attach('/path/to/file.ext') ){
echo $this->email->print_debugger();
}
并且不会引发任何错误。
我只注意到发出send命令后未附加附件
$this->email->send();
实际上,电子邮件已发送,但显然没有附件,但也没有
$this->email->message()
内容-只是一个空的电子邮件正文。在调用send()函数之前,似乎不会真正填充print_debugger()函数。如果我有意指向一个不存在的文件,则print_debugger()函数将引发此错误(仅在调用send()函数之后):
Unable to locate the following email attachment: /path/to/file.ext<br />Your message
has been successfully sent using the following protocol: sendmail<br /><pre>
User-Agent: CodeIgniter
Date: Thu, 23 May 2013 09:27:49 -0400
<snip>
当我在send()函数之前调用print_debugger()函数时,结果只是一个空数组(我在猜测,因为该调用的输出只是
<pre> </pre>
)。我希望在从框架内调用send()函数之前捕获此错误。
我确实知道我可以在本地使用PHP来检查file_exists,但恕我直言,恕我直言,对于Codeigniter来说,它比它更早抛出一些错误。
if( file_exists('/path/to/file.ext') ):
$this->email->attach('/path/to/file.ext');
else:
echo 'ERROR';
endif;
有想法/建议/意见吗?
最佳答案
这本身不是CodeIgniter的特定功能。我认为您正在寻找PHP Exceptions。例:
try {
$this->email->attach('/path/to/file.ext');
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage();
}
关于codeigniter - Codeigniter电子邮件->附加错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16716789/