通过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和editplus正则表达式去除空白行

php和editplus正则表达式去除空白行

去除字符串内部的空行: 复制代码 代码如下: $str = preg_replace("/(\s*?\r?\n\s*?)+/","\n",$str); 去除全部...

PHP实现仿Google分页效果的分页函数

本文实例讲述了PHP实现仿Google分页效果的分页函数。分享给大家供大家参考。具体如下: /** * 分页函数 * @param int $total 总页数 * @par...

浅谈使用PHP开发微信支付的流程

下面以PHP语言为例,对微信支付的开发流程进行一下说明。 1.获取订单信息 2.根据订单信息和支付相关的账号生成sign,并且生成支付参数 3.将支付参数信息POST到微信服务器,获取返...

PHP目录函数实现创建、读取目录教程实例

今天主要介绍在PHP网站开发中文件目录函数的应用。在PHP网站开发中,我们时常需要读取目录文件信息或者创建目录以存放必要的文件,而当目录文件大小超出规定大小时我们又需要删除目录文件,如手...

Php Image Resize图片大小调整的函数代码

复制代码 代码如下: function my_image_resize($src_file, $dst_file, $dst_width=32, $dst_height=32) { if...