通过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实现支持中文的文件下载功能示例

php实现支持中文的文件下载功能示例

前言 本文主要给大家介绍了关于php实现支持中文的文件下载功能的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。 问题说明 文件下载,通常有一种最为简单的方法...

PHP 自定义可控的字符串加密解密方法函数

以下这个是我在项目中常用的字符串加密解密函数,供大家参考有个好处是每次调用加密后的数据都是不一样的但都能解密回原来的数据。/**  * @param $string&n...

php利用header函数实现文件下载时直接提示保存

复制代码 代码如下: <?php $filename = '路径+实际文件名'; //文件的类型 header('Content-type: application/pdf');...

PHP实现路由映射到指定控制器

PHP实现路由映射到指定控制器

自定义路由的功能,指定到pathinfo的url上,再次升级之前的脚本  SimpleLoader.php <?php class SimpleLoade...

php+AJAX传送中文会导致乱码的问题的解决方法

//如果传送参数是直接赋予的,就会产生乱码! 复制代码 代码如下:http_request.open("POST",url,true); http_request.setRequestH...