通过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简单实现加减乘除计算器

用php实现加减乘除计算器。代码很简单哦! 复制代码 代码如下: <?php header("content-type:text/html;charset=utf-8"); ses...

探讨Smarty中如何获取数组的长度以及smarty调用php函数的详解

Smarty中如何获取数组的长度 前提假设:分配了一个数组array给Smarty,假设Smarty的分界符为'{' 和'}'。在很多资料上都看到,在Smarty中要求数组的长度时,可以...

php visitFile()遍历指定文件夹函数

注:visitFile()有少量修改 复制代码 代码如下: <? // 查看指定文件夹的文件 $fileList = array(); function visitFile($pa...

零基础php编程好学吗

PHP编程语言对于新手而言,非常容易上手,不乏有很多人通过自学找到了高薪的工作。不管自学还是通过参加培训进行学习,PHP开发工程师是保持如何的晋级过程呢?如何考究自己学习过程中的实力水平...

PHP实现提取一个图像文件并在浏览器上显示的代码

去年做过一个项目,要把用户上传的图像文件列出文字清单,当用户点击一个文件名后,就可以显示这个图像. 因为要考虑兼容各种不同的图像格式, 我使用了GD库, 判断出具体是那种图像文件(MIN...