通过Email发送PHP错误的方法


Posted in PHP onJuly 20, 2015

本文实例讲述了通过Email发送PHP错误的方法。分享给大家供大家参考。具体实现方法如下:

<?php
// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line, $vars){
  $email = "
    <p>An error ($number) occurred on line
    <strong>$line</strong> and in the <strong>file: $file.</strong>
    <p> $message </p>";
  $email .= "<pre>" . print_r($vars, 1) . "</pre>";
  $headers = 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
  // Email the error to someone...
  error_log($email, 1, 'you@youremail.com', $headers);
  // Make sure that you decide how to respond to errors (on the user's side)
  // Either echo an error message, or kill the entire project. Up to you...
  // The code below ensures that we only "die" if the error was more than
  // just a NOTICE.
  if ( ($number !== E_NOTICE) && ($number < 2048) ) {
    die("There was an error. Please try again later.");
  }
}
// We should use our custom function to handle errors.
set_error_handler('nettuts_error_handler');
// Trigger an error... (var doesn't exist)
echo $somevarthatdoesnotexist;

希望本文所述对大家的php程序设计有所帮助。

PHP 相关文章推荐
用js进行url编码后用php反解以及用php实现js的escape功能函数总结
Feb 08 PHP
ThinkPHP的RBAC(基于角色权限控制)深入解析
Jun 17 PHP
基于php中使用excel的简单介绍
Aug 02 PHP
递归删除一个节点以及该节点下的所有节点示例
Mar 19 PHP
PHP正则提取不包含指定网址的图片地址的例子
Apr 21 PHP
PHP检测字符串是否为UTF8编码的常用方法
Nov 21 PHP
php技术实现加载字体并保存成图片
Jul 27 PHP
thinkPHP js文件中U方法不被解析问题的解决方法
Dec 05 PHP
利用php获得flv视频长度的实例代码
Oct 26 PHP
PHP生成腾讯云COS接口需要的请求签名
May 20 PHP
详解关于php的xdebug配置(编辑器vscode)
Jan 29 PHP
PHP检测一个数组有没有定义的方法步骤
Jul 20 PHP
php实现编辑和保存文件的方法
Jul 20 #PHP
php数组生成html下拉列表的方法
Jul 20 #PHP
php生成过去100年下拉列表的方法
Jul 20 #PHP
PHP基于文件存储实现缓存的方法
Jul 20 #PHP
详解PHP错误日志的获取方法
Jul 20 #PHP
php实现网站顶踩功能的完整前端代码
Jul 19 #PHP
php实现上传图片文件代码
Jul 19 #PHP
You might like
一个目录遍历函数
2006/10/09 PHP
ThinkPHP模板中判断volist循环的最后一条记录的验证方法
2014/07/01 PHP
php switch语句多个值匹配同一代码块应用示例
2014/07/29 PHP
PHP解码unicode编码的中文字符代码分享
2014/08/13 PHP
php实现的操作excel类详解
2016/01/15 PHP
php 数组元素快速去重
2017/05/05 PHP
判断是否输入完毕再激活提交按钮
2006/06/26 Javascript
使用JavaScript开发IE浏览器本地插件实例
2015/02/18 Javascript
JS实现IE状态栏文字缩放效果代码
2015/10/24 Javascript
jQuery 1.9.1源码分析系列(十)事件系统之主动触发事件和模拟冒泡处理
2015/11/24 Javascript
AngularJS框架中的双向数据绑定机制详解【减少需要重复的开发代码量】
2017/01/19 Javascript
JavaScript解析JSON格式数据的方法示例
2017/01/24 Javascript
vue-router 中router-view不能渲染的解决方法
2017/05/23 Javascript
JS传播事件、取消事件默认行为、阻止事件传播详解
2017/08/14 Javascript
简述vue路由打开一个新的窗口的方法
2018/11/29 Javascript
jQuery实现的点击图片居中放大缩小功能示例
2019/01/16 jQuery
vue 单页应用和多页应用的优劣
2020/10/22 Javascript
Python2.x中文乱码问题解决方法
2015/06/02 Python
Python实现批量修改文件名实例
2015/07/08 Python
python脚本爬取字体文件的实现方法
2017/04/29 Python
使用 Python 实现简单的 switch/case 语句的方法
2018/09/17 Python
python 多个参数不为空校验方法
2019/02/14 Python
Python+OpenCV+图片旋转并用原底色填充新四角的例子
2019/12/12 Python
np.dot()函数的用法详解
2020/01/17 Python
python如何删除列为空的行
2020/07/17 Python
Python如何解除一个装饰器
2020/08/07 Python
python查询MySQL将数据写入Excel
2020/10/29 Python
详解rem 适配布局
2018/10/31 HTML / CSS
沙特阿拉伯电子产品和家用电器购物网站:Black Box
2019/07/24 全球购物
Myprotein瑞士官方网站:运动营养和健身网上商店
2019/09/25 全球购物
污水厂厂长岗位职责
2014/01/04 职场文书
公交公司毕业生求职信
2014/02/15 职场文书
小学生三分钟演讲稿
2014/08/18 职场文书
护士岗前培训心得体会
2016/01/08 职场文书
python for循环赋值问题
2021/06/03 Python
利用Apache Common将java对象池化的问题
2022/06/16 Servers