PHP 错误与异常 笔记与总结(7)将错误日志以邮件方式发送

当系统发生了很严重的问题,需要立刻发送给管理员。可以通过 error_log() 将错误以邮件形式发送到邮箱。

在 php.ini 中设置:

sendmail_from = 472323087@qq.com

然后设置:

sendmail_path = "G:sendmailsendmail.exe -t"

其中:G:sendmailsendmail.exe 是邮件客户端的地址。

代码:

<?php
//关闭错误显示
ini_set('display_errors', 0);
//开启错误日志功能
ini_set('log_errors', 'on');
//显示所有错误
error_reporting(-1);

//发送错误
error_log('当前系统被攻击,产生了致命错误', 1, '472323087@qq.com'); //参数 1 表示以邮件形式发送错误
原文地址:https://www.cnblogs.com/dee0912/p/4523969.html