通过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 字符串函数收集

1查找字符位置函数: strpos($str,search,[int]):查找search在$str中的第一次位置从int开始; stripos($str,search,[int]):函...

php 命名空间(namespace)原理与用法实例小结

本文实例讲述了php 命名空间(namespace)原理与用法。分享给大家供大家参考,具体如下:命名空间一个最明确的目的就是解决重名问题,PHP中不允许两个函数或者类出现相同的名字,否则会...

php批量缩放图片的代码[ini参数控制]

首先使用一个ini文件来设置要缩放的大小,其中为宽或高0的则为图片放大或缩小,都为0则还是原大小,都不为0都拉抻成指定的大小。 注意:ini文件使用php解释时为注释文件,什么也没有输出...

探讨Smarty中如何获取数组的长度以及smarty调用php函数的详解

Smarty中如何获取数组的长度 前提假设:分配了一个数组array给Smarty,假设Smarty的分界符为'{' 和'}'。在很多资料上都看到,在Smarty中要求数组的长度时,可以...

PHP输出图像imagegif、imagejpeg与imagepng函数用法分析

本文实例讲述了PHP输出图像imagegif、imagejpeg与imagepng函数用法。分享给大家供大家参考,具体如下: imagegif()、imagejpeg()、imagepn...