通过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 数组的指针操作实现代码

/** * 将数组的内部指针倒回一位 * @param array &$arr * @return mixed 返回前一个单元的值,当没有更多单元时返回 FALSE * 如果数组包含空的...

PHP实现普通hash分布式算法简单示例

本文实例讲述了PHP实现普通hash分布式算法。分享给大家供大家参考,具体如下: <?php /* * 普通hash分布式算法 * @param $key * @...

浅谈php优化需要注意的地方

我们在编写程序时,总是想要使自己的程序占用资源最小,运行速度更快,代码量更少。往往我们在追求这些的同时却失去了很多东西。下面我想讲讲我对PHP优化的理解。优化的目的是花最少的代价换来最快...

PHP文件与目录操作示例

本文实例讲述了PHP文件与目录操作。分享给大家供大家参考,具体如下: 文件目录相关函数 <?php // 输出目录中的文件 function outputcurfile...

php数组函数序列之array_splice() - 在数组任意位置插入元素

array_splice定义和用法 array_splice() 函数与 array_slice() 函数类似,选择数组中的一系列元素,但不返回,而是删除它们并用其它值代替。 如果提供了...