通过Email发送PHP错误的方法

yipeiwu_com5年前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基于简单递归函数求一个数阶乘的方法。分享给大家供大家参考,具体如下: 一、问题: 求一个数a的阶乘,那么,a!=a*(a-1)*(a-2)*(a-3)*……*2*1....

PHP设计模式之工厂模式(Factory Pattern)的讲解

面向对象编程中,工厂模式是我们最常用的实例化对象模式,工厂类就是一个专门用来创建其它对象的类,工厂类在多态性编程实践中是非常重要的。它允许动态替换类,修改配置,会使应用程序更加灵活。掌握...

PHP聊天室简单实现方法详解

PHP聊天室简单实现方法详解

本文实例讲述了PHP聊天室简单实现方法。分享给大家供大家参考,具体如下: 用户 => 客服 (先把信息入库,然后通过ob+长连接不断从数据库查询数据发送给客服) 客服 =>...

php程序的国际化实现方法(利用gettext)

步骤一:搭建环境 1,首先查看你的php扩展目录下是否有php_gettext.dll这个文件,如果没有,这就需要你 下载一个或是从其他地方拷贝一个,然后放到php扩展目录。 2,打开p...

PHP程序61条面向对象分析设计的经验小结

(1)所有数据都应该隐藏在所在的类的内部。 (2)类的使用者必须依赖类的共有接口,但类不能依赖它的使用者。 (3)尽量减少类的协议中的消息。 (4)实现所有类都理解的最基本公有接口[例如...