通过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 相关文章推荐
xajax写的留言本
Nov 25 PHP
php判断正常访问和外部访问的示例
Feb 10 PHP
ThinkPHP实现支付宝接口功能实例
Dec 02 PHP
PHP中使用imagick生成PSD文件缩略图教程
Jan 26 PHP
php实现用手机关闭计算机(电脑)的方法
Apr 22 PHP
php实现的mongodb操作类
May 28 PHP
php使用array_search函数实现数组查找的方法
Jun 12 PHP
微信支付开发维权通知实例
Jul 12 PHP
ThinkPHP中session函数详解
Sep 14 PHP
完美解决在ThinkPHP控制器中命名空间的问题
May 05 PHP
Laravel中encrypt和decrypt的实现方法
Sep 24 PHP
PHP中单例模式的使用场景与使用方法讲解
Mar 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实现的Captcha验证码类实例
2014/09/22 PHP
TP3.2框架分页相关实现方法分析
2020/06/03 PHP
javascript css在IE和Firefox中区别分析
2009/02/18 Javascript
在页面上用action传递参数到后台出现乱码的解决方法
2013/12/31 Javascript
jQuery异步获取json数据方法汇总
2014/12/22 Javascript
jQuery插件jcrop+Fileapi完美实现图片上传+裁剪+预览的代码分享
2015/04/22 Javascript
Webwork 实现文件上传下载代码详解
2016/02/02 Javascript
喜大普奔!jQuery发布 3.0 最终版
2016/06/12 Javascript
jQuery 插件封装的方法
2016/11/16 Javascript
js轮播图透明度切换(带上下页和底部圆点切换)
2017/04/27 Javascript
JS实现计算小于非负数n的素数的数量算法示例
2019/02/26 Javascript
java和js实现的洗牌小程序
2019/09/30 Javascript
JS变量提升原理与用法实例浅析
2020/05/22 Javascript
基于canvasJS在PHP中制作动态图表
2020/05/30 Javascript
微信小程序实现页面左右滑动
2020/11/16 Javascript
Python数据结构与算法之字典树实现方法示例
2017/12/13 Python
Python实现正整数分解质因数操作示例
2018/08/01 Python
Django中的forms组件实例详解
2018/11/08 Python
django之状态保持-使用redis存储session的例子
2019/07/28 Python
Python input函数使用实例解析
2019/11/22 Python
python编程进阶之类和对象用法实例分析
2020/02/21 Python
Python实现常见的几种加密算法(MD5,SHA-1,HMAC,DES/AES,RSA和ECC)
2020/05/09 Python
Python 实现进度条的六种方式
2021/01/06 Python
基于HTML5代码实现折叠菜单附源码下载
2015/11/27 HTML / CSS
美国最大点评网站:Yelp
2018/02/14 全球购物
分厂厂长岗位职责
2013/12/29 职场文书
企业业务员岗位职责
2014/03/14 职场文书
房屋转让协议书
2014/04/11 职场文书
《与朱元思书》的教学反思
2014/04/17 职场文书
励志演讲稿600字
2014/08/21 职场文书
总经理检讨书范文
2015/02/16 职场文书
2015年质量月活动总结报告
2015/03/27 职场文书
三好学生主要事迹怎么写
2015/11/03 职场文书
外出考察学习心得体会
2016/01/18 职场文书
OpenCV-Python实现轮廓拟合
2021/06/08 Python
MySQL 亿级数据导入导出及迁移笔记
2021/06/18 MySQL