在CodeIgniter中,如何将PHP错误消息通过电子邮件发送给我?
我想通过电子邮件接收错误日志。例如,如果出现警告级别
错误消息,我想收到一封有关它的电子邮件。
I'd like to receive error logs via email. For example, if a Warning-level
error message should occur, I'd like to get an email about it.
如何在CodeIgniter中使用它?
How can I get that working in CodeIgniter?
您可以扩展Exception核心类来做到这一点。
You could extend the Exception core class to do it.
可能必须调整对CI电子邮件类别的引用,不确定是否可以从这样的库中实例化它。我自己没有使用CI的电子邮件课程,我一直在使用Swift Mailer库。
Might have to adjust the reference to CI's email class, not sure if you can instantiate it from a library like this. I don't use CI's email class myself, I've been using the Swift Mailer library. But this should get you on the right path.
制作一个文件MY_Exceptions.php并将其放在/ application / libraries /中(对于CI,则放在/ application / core /中) 2)
Make a file MY_Exceptions.php and place it in /application/libraries/ (Or in /application/core/ for CI 2)
class MY_Exceptions extends CI_Exceptions {
function __construct()
{
parent::__construct();
}
function log_exception($severity, $message, $filepath, $line)
{
if (ENVIRONMENT === 'production') {
$ci =& get_instance();
$ci->load->library('email');
$ci->email->from('your@example.com', 'Your Name');
$ci->email->to('someone@example.com');
$ci->email->cc('another@another-example.com');
$ci->email->bcc('them@their-example.com');
$ci->email->subject('error');
$ci->email->message('Severity: '.$severity.' --> '.$message. ' '.$filepath.' '.$line);
$ci->email->send();
}
parent::log_exception($severity, $message, $filepath, $line);
}
}