通过Email发送PHP错误的方法

yipeiwu_com5年前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程序设计有所帮助。

相关文章

mac下使用brew配置环境的步骤分享

首先 开启web共享。 配置 httpd.conf 加入php拓展 /etc/apache2/httpd.conf 如出现 ULIMIT_MAX_FILES="ulimit -S -n...

关于php 接口问题(php接口主要也就是运用curl,curl函数)

接口问题php调用接口最主要的就是使用curl抓取信息复制代码 代码如下:$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);&n...

php实现在多维数组中查找特定value的方法

本文实例讲述了php实现在多维数组中查找特定value的方法。分享给大家供大家参考。具体如下: 最近做项目,需要从多维数组中查找是否含有特定的key和其对应特定的value,并清除该条数...

PHP-redis中文文档介绍

phpredis是php的一个扩展,效率是相当高有链表排序功能,对创建内存级的模块业务关系 很有用;以下是redis官方提供的命令使用技巧: 下载地址如下: https://...

PHP回调函数概念与用法实例分析

本文实例讲述了PHP回调函数概念与用法。分享给大家供大家参考,具体如下: 一、回调函数的概念 先看一下C语言里的回调函数:回调函数就是一个通过函数指针调用的函数。如果你把函数的指针(地址...