通过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实现替换手机号中间数字为*号及隐藏IP最后几位的方法

本文实例讲述了php实现替换手机号中间数字为*号及隐藏IP最后几位的方法。分享给大家供大家参考,具体如下: $string = "13826589549"; $pattern = "...

php数组函数序列之array_search()- 按元素值返回键名

array_search()定义和用法 array_search() 函数与 in_array() 一样,在数组中查找一个键值。如果找到了该值,匹配元素的键名会被返回。如果没找到,则返回...

thinkphp多表查询两表有重复相同字段的完美解决方法

框架:thinkphp 版本:3.2.3 内容:查询语句 解决问题:重复字段问题 $Data = M('a')->where($where) ->Fiel...

php设计模式 Strategy(策略模式)

php设计模式 Strategy(策略模式)

抽象策略(Strategy)角色:定义所有支持的算法的公共接口。通常是以一个接口或抽象来实现。Context使用这个接口来调用其ConcreteStrategy定义的算法。 具体策略(C...

PHP简单实现记录网站访问量功能示例

PHP简单实现记录网站访问量功能示例

本文实例讲述了PHP简单实现记录网站访问量功能。分享给大家供大家参考,具体如下: tongji/index.php文件: $file = dirname(__FILE__).'/to...