通过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中getservbyport与getservbyname函数用法实例

本文实例讲述了php中getservbyport与getservbyname函数用法。分享给大家供大家参考。具体如下: 复制代码 代码如下: string getservbyport (...

php错误日志简单配置方法

本文实例讲述了php配置错误日志的方法。分享给大家供大家参考,具体如下: php.ini: ; 错误日志 log_errors = On ; 显示错误 display_errors...

php实现自定义中奖项数和概率的抽奖函数示例

本文实例讲述了php实现自定义中奖项数和概率的抽奖函数。分享给大家供大家参考,具体如下: <?php /* * 一个抽奖类,精确到万分之一 * 三个步骤:1.接受一个中...

php实现的数组转xml案例分析

本文实例讲述了php实现的数组转xml。分享给大家供大家参考,具体如下: 0x00 需求 最近要做百度、360、神马搜索的网站sitemap,三家的格式都是xml,然而具体的细节还有有差...

解析PHP高效率写法(详解原因)

1.尽量静态化:如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍。当然了,这个测试方法需要在十万级以上次执行,效果才明显。其实静态方法和非静...