通过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+ajax实现无刷新分页的方法

本文实例讲述了php+ajax实现无刷新分页的方法。分享给大家供大家参考。具体实现方法如下: 这是一款基于原生态的php +js +ajax 的分页程序实例,我们详细的从数据库创建到js...

如何避免PHP实例代码中的一些坏代码

做PHP开发已经有快一年的时间了,在这一年的时间中,学习了很多生产环境中的技巧,学习了很多东西,期间也阅读了一些优秀的源码和关于代码的书,对写代码这一块有了一定的思考,也看过很多别人写的...

php采集时被封ip的解决方法

在网上找了一些资料都没有找到,功夫不负有心人啊,在找的时侯有一个人提到了用搜索引擎爬虫蜘蛛的USERAGENT。虽然只提到一点点我还是想到了,列出我的解决方法, 1.使用Snoopy或c...

PHP的变量类型和作用域详解

PHP中变量的作用域可以分为:超全局(全局变量的特殊类型,在局部范围里可直接使用),全局,局部,静态(是局部变量的特殊类型)在PHP中,全局变量实际上是静态全局变量,如果不用unset显...

php异常处理捕获错误整理

PHP的错误报告有三种: 1、错误,语法解析错误,致命错误 2、警告 3、注意 后果: 错误 -> 致命错误,会终止已下程序的执行,语法错误的话,PHP压根就没执行。 警告 -&g...