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

相关文章

使用ltrace工具跟踪PHP库函数调用的方法

本文实例讲述了使用ltrace工具跟踪PHP库函数调用的方法。分享给大家供大家参考,具体如下: 可能大家已经很熟悉使用strace来跟踪系统调用,今天介绍一个跟踪库函数的利器ltrace...

PHP编程中尝试程序并发的几种方式总结

本文大约总结了PHP编程中的五种并发方式: 1.curl_multi_init 文档中说的是 Allows the processing of multiple cURL handles...

PHP JSON出错:Cannot use object of type stdClass as array解决方法

php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误: 复制代码 代码如下: Cannot use object of type...

高质量PHP代码的50个实用技巧必备(上)

50个高质量PHP代码的实用技巧,希望大家喜欢。 1.不要使用相对路径 常常会看到: require_once('../../lib/some_class.php'); 该...

PHP调用其他文件中的类

首先在一个tool.php文件中声明一个类: <?php class tool { function say(){ $result="Hello,Worl...