通过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许愿墙模块功能分析

许愿墙模块功能分析一,热点技术1,实现可拖放DOM技术移动许愿字条可拖放DOM模式(Draggable DOM pattern)的宗旨在于允许浏览者自己定义页面中各元素的位置,并且,只需...

PHP递归调用数组值并用其执行指定函数的方法

本文实例讲述了PHP递归调用数组值并用其执行指定函数的方法。分享给大家供大家参考。具体分析如下: 以下为wordpress原代码,为了偷懒,简单修改一下以适用其它函数 /** *...

PHP 删除文件与文件夹操作 unlink()与rmdir()这两个函数的使用

先看一下代码 复制代码 代码如下: <? function deldir($dir) { //先删除目录下的文件: $dh=opendir($dir); while ($file=...

php实现读取超大文件的方法

通常来说在php读取大文件的时候,我们采用的方法一般是一行行来讲取,而不是一次性把文件全部写入内存中,这样会导致php程序卡死,下面就给大家介绍这样一个例子。 读取大文件最后几行数据:...

php下使用SimpleXML 处理XML 文件

1 SimpleXML 简介 要处理XML 文件,有两种传统的处理思路:SAX 和DOM。SAX 基于事件触发机制, 对XML 文件进行一次扫描,完成要进行的处理;DOM 则将整个XML...