通过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基于curl实现随机ip地址抓取内容的方法

本文实例讲述了php基于curl实现随机ip地址抓取内容的方法。分享给大家供大家参考,具体如下: 使用php curl 我们可以模仿用户行为,既可以设置我们访问的ip及浏览器信息还可以设...

thinkphp中U方法按路由规则生成url的方法

如下所示: //更改模块配置文件 'URL_ROUTER_ON' => true, 'URL_ROUTE_RULES'=>[]//编写路由优化 tp开启路由后,使...

php短址转换实现方法

php短址转换实现方法

本文实例讲述了php短址转换实现方法。分享给大家供大家参考。具体分析如下: 从昨天下午到现在 推翻了一个又一个的信息存储方案,从mysql到加上内存不受限制的file_get_conte...

php数组索引与键值操作技巧实例分析

本文实例讲述了php数组索引与键值操作技巧。分享给大家供大家参考。具体如下: <?php $array = array("a", "b","c"); //定义数组...

PHP数组传递是值传递而非引用传递概念纠正

在调用函数时通过将PHP数组作为实参赋给形参,在函数中修改,并不会影响到数组本身。 说明此过程中的传递为值传递,数组变量并非是指向此数组本身的引用,PHP数组本身以值的形式存在,同时形参...