通过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 相关文章推荐
php中的数组操作函数整理
Aug 18 PHP
IIS php环境配置PHP5 MySQL5 ZendOptimizer phpmyadmin安装与配置
Nov 18 PHP
PHP实现视频文件上传完整实例
Aug 28 PHP
php去除二维数组的重复项方法
Nov 03 PHP
php打包网站并在线压缩为zip
Feb 13 PHP
PHP中SERIALIZE和JSON的序列化与反序列化操作区别分析
Oct 11 PHP
php使用正则表达式去掉html中的注释方法
Nov 03 PHP
PHP实现的链式队列结构示例
Sep 15 PHP
PHP封装的非对称加密RSA算法示例
May 28 PHP
php web环境和命令行环境下查找php.ini的位置
Jul 17 PHP
PHP的JSON封装、转变及输出操作示例
Sep 27 PHP
laravel框架路由分组,中间件,命名空间,子域名,路由前缀实例分析
Feb 18 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
浅析php header 跳转
2013/06/17 PHP
使用laravel的Eloquent模型如何获取数据库的指定列
2019/10/17 PHP
JavaScript开发规范要求(规范化代码)
2010/08/16 Javascript
lyhucSelect基于Jquery的Select数据联动插件
2011/03/29 Javascript
使用jQuery实现dropdownlist的联动效果(sharepoint 2007)
2011/03/30 Javascript
javascript实例分享---具有立体效果的图片特效
2014/06/08 Javascript
如何使用HTML5地理位置定位功能
2015/04/27 Javascript
设计模式中的facade外观模式在JavaScript开发中的运用
2016/05/18 Javascript
jQuery Ajax传值到Servlet出现乱码问题的解决方法
2016/10/09 Javascript
Javascript使用uploadify来实现多文件上传
2016/11/16 Javascript
微信小程序 动态绑定数据及动态事件处理
2017/03/14 Javascript
js canvas实现QQ拨打电话特效
2017/05/10 Javascript
js获取浏览器地址(获取第1个斜杠后的内容)
2019/09/03 Javascript
关于Layui Table隐藏列问题
2019/09/16 Javascript
javascript设计模式 ? 工厂模式原理与应用实例分析
2020/04/09 Javascript
[01:32]完美世界DOTA2联赛10月29日精彩集锦
2020/10/30 DOTA
Python实现读取邮箱中的邮件功能示例【含文本及附件】
2017/08/05 Python
Python OpenCV 调用摄像头并截图保存功能的实现代码
2019/07/02 Python
Python数学形态学实例分析
2019/09/06 Python
解决Python使用列表副本的问题
2019/12/19 Python
浅谈python print(xx, flush = True) 全网最清晰的解释
2020/02/21 Python
python实现TCP文件传输
2020/03/20 Python
Jupyter Notebook输出矢量图实例
2020/04/14 Python
解决Jupyter无法导入已安装的 module问题
2020/04/17 Python
阿根廷网上配眼镜:SmartBuyGlasses阿根廷
2016/08/19 全球购物
英国工具中心:UK Tool Centre
2017/07/10 全球购物
英国领先的汽车轮胎和快速健康中心:Kwik Fit
2017/10/29 全球购物
新加坡网上美容店:Hermo新加坡
2019/06/19 全球购物
PHP如何防止SQL注入
2014/05/03 面试题
渗透攻击的测试步骤
2014/06/07 面试题
生日宴会策划方案
2014/06/03 职场文书
本溪关门山导游词
2015/02/09 职场文书
公司财务部岗位职责
2015/04/14 职场文书
小学数学继续教育研修日志
2015/11/13 职场文书
家庭教育培训学习心得体会
2016/01/14 职场文书
Go 通过结构struct实现接口interface的问题
2021/10/05 Golang