通过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自定义排序uasort函数示例【二维数组按指定键值排序】

本文实例讲述了php自定义排序uasort函数。分享给大家供大家参考,具体如下: 项目需要风险排序,按 I(安全)<L(低风险)<M(中风险)<H(高风险) 的级别来排...

php使用CURL不依赖COOKIEJAR获取COOKIE的方法

本文实例讲述了php使用CURL不依赖COOKIEJAR获取COOKIE的方法。分享给大家供大家参考。具体分析如下: PHP中CURL类是一个非常牛逼的工具类,具体怎么牛逼就不啰嗦了。...

php 基础函数

话不多说,如下所示: <?php //生成随机数 和 时间函数 //echo rand(); //echo "<br>"; //echo rand(0,10...

mac系统下安装多个php并自由切换的方法详解

前言 最近工作中遇到一个问题,需要实现在mac系统下安装多个php并实现自由切换,通过查找相关的资料找到了解决的方法,所以想着总结下来,方便大家和自己学习参考,下面话不多说,来看看的介绍...

上传多个文件的PHP脚本

译者注:本文的原名是《Creating a Multi-File Upload Script in PHP》。我个个觉得这文章...