通过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程序设计有所帮助。

相关文章

10款PHP开源商城系统汇总介绍

  在当今经济危机的大环境下,网上购物越来越来吃香,网上开店成本低,快捷方便,出名的电子商务网站有淘宝,拍拍,Ebay或是最新的百度有啊,这些网站都提供开店的机会,如果是想自己搭建购物平...

学习php设计模式 php实现策略模式(strategy)

学习php设计模式 php实现策略模式(strategy)

一、意图 定义一系列的算法,把它们一个个封装起来,并且使它们可相互替换。策略模式可以使算法可独立于使用它的客户而变化 策略模式变化的是算法 二、策略模式结构图   三、策略模式...

php统计文件大小,以GB、MB、KB、B输出

使用filesize()函数命令实现文件大小的统计,要求:1,以GB、MB、KB、B中的一个输出;2.数量级必须大于1小于1024,并保留两位小数;   开始动工: 复制代码 代码如下:...

10个超级有用的PHP代码片段果断收藏

10个超级有用的PHP代码片段果断收藏

本文小编将为你奉上10个超级有用的PHP代码片段。 1.查找Longitudes与Latitudes之间的距离 function getDistanceBetweenPointsN...

PHP单态模式简单用法示例

本文实例讲述了PHP单态模式简单用法。分享给大家供大家参考,具体如下: 单态类就是只能实例化一次的类 <?php /* 作者 : shyhero */ class De...