通过Email发送PHP错误的方法

yipeiwu_com6年前PHP代码库

本文实例讲述了通过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基于 swoole 实现的异步处理任务功能示例

本文实例讲述了php基于 swoole 实现的异步处理任务功能。分享给大家供大家参考,具体如下: 安装swoole: 下载官方swoole压缩包,解压进入目录 $ cd swoole...

PHP树形结构tree类用法示例

PHP树形结构tree类用法示例

本文实例讲述了PHP树形结构tree类用法。分享给大家供大家参考,具体如下: <?php include 'tree.class.php'; //模拟数据库 $data...

php防止站外远程提交表单的方法

本文实例讲述了php防止站外远程提交表单的方法,分享给大家供大家参考。具体实现方法如下: 一般来说防止站长提交表单无非就是对每一次打开表单或提交数据都会需要加一个token来进行验证了,...

php magic_quotes_gpc的一点认识与分析

blankyao 说“学习的过程就是不断的发现错误,不断的改正错误”; 先看下手册上怎么说的吧! 对一般人来说看下前两段就可以了 Magic Quotes 代码: Magic Quote...

PHP面向对象自动加载机制原理与用法分析

PHP面向对象自动加载机制原理与用法分析

本文实例讲述了PHP面向对象自动加载机制原理与用法。分享给大家供大家参考,具体如下: 在学习PHP的面向对象的时候,会知道很多“语法糖”,也就是魔术方法。有一个加自动加载的魔术方法,叫:...