search
HomeBackend DevelopmentPHP Tutorial用PHP即?捕捉PHP原始?中的??并?送email通知

??PHP的朋友都知道,其?最?心的就是程序中出?一些?常或??,?些??如果?出到用?的?幕?把用????,甚至?此?了工作,如果不?出到?幕就得想?法??到日?中,但是似乎不是每?人都有查看??日?的??,?了解????尬的??,所以我?了?段代?,其用意就是?我??的php程式出?的?候把???容捕捉出?然後?到我?的email?.
先看效果:

 

Define('SYS_DEBUG',false);IF(SYS_DEBUG) {ini_set('display_errors','on');Error_reporting(E_ALL);//上?后使用??定Error_reporting(E_ERROR | E_WARNING | E_PARSE);}Else{ini_set('display_errors','off');Error_reporting(0);}//??捕捉Register_shutdown_function('Fun::Error');Class Fun{/**通用出??理参数:要?出的?容,是否?止?行程序?明:有?值??函式可以用??出自定?的???容另外?可以配合Register_shutdown_function??自?抓取???容,??抓取的???容?送到Email?Register_shutdown_function的?制是程序?行完?或中途出???用函?如果是自?抓取???被?用,??取得最後一次出?的?容,如果???有???容?跳出返回:?容?被直接?出至?幕或Email?用法:Fun::Error('???容');Fun::Error('???容',False);/**/Public Static Function Error($M='',$E=True){$ErrTpl='<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><table cellspacing="0" cellpadding="0" border="0"><tr><td style="padding:5px;background-color:#F57900;font-size:13px;border:1px solid #444;color:#222;">{$M}</td></tr></table>';$M=Trim($M);IF($M!='') {//手工?用$M=' <b>注意:</b> '.$M;Echo Strtr($ErrTpl,Array('{$M}'=>$M));unSet($ErrTpl);IF($E===True) {Die();}Return ;}Else{//程式?行完?自?抓取????用$M=error_get_last();//取得最後?生的??IF(!Is_array($M) Or Count($M)<4) {Unset($M);Return ;}IF(!File_Exists($M['file'])) {Unset($M);Return ;}//取得5行出???代?,如果取不到?容,?明出??案不存在$E=Array_slice(File($M['file']),($M['line']-4),5);IF(!Is_array($E)) {Unset($M,$E);Return ;}$E['M']='';For($i=0;$i<5;$i++) {$E[$i]=isSet($E[$i]) ? $E[$i] : '';$E['M'].='  ';$E['M'].=($i==3) ? '<b>'.(($M['line']-3)+($i+1)).'</b>' : (($M['line']-3)+($i+1));$E['M'].=': '.Htmlspecialchars($E[$i],ENT_QUOTES,'UTF-8').'<br>';}$E=&$E['M'];$M='<b>自?捕捉到有???生!</b><br><br><b>??描述:</b><br>  <b>'.$M['file'].'</b>的第<b>'.$M['line'].'</b>行出?了?型?<b>'.$M['type'].'</b>的??:<br>  '.$M['message'].'<br><br><b>??代?:</b><br>'.$E.'<br>'.self::now('Y-m-d H:i:s',time()).'<br>';$M=Strtr($ErrTpl,Array('{$M}'=>$M));unSet($ErrTpl);$G=seft::getG('SYS','config');IF(!self::Mail2($G['Spe'],'警告: '.$G['Tit'].' 出? PHP 程式??!',$M) And SYS_DEBUG===True){throw new Exception('警告: '.$G['Tit'].' 出? PHP 程式??!<br><br>'.$M);}IF(SYS_DEBUG) {Echo $M;}unSet($E,$M,$G);Die();}}/**发送??参数:收件人,?件??(不可有?行符),?件?容(行?行之?必?用\n分隔,每行不可超?70?字符)?明:?用PHP?置函式Mail?送??返回:返回布?值用法:$IsSend=Fun::Mail2($email,$tit,$msg);/**/Public Static Function Mail2($to,$tit,$msg) {IF(Filter_var($to,FILTER_VALIDATE_EMAIL)==''){throw new Exception('??地址??!');}$tit='=?UTF-8?B?'.Base64_Encode($tit).'?=';$msg = str_replace("\n.","\n..",$msg);     //Windows如果在一行开头发现一个句号则会被删掉,要避免此问题将单个句号替换成两个句号Return Mail($to,$tit,$msg,'From:'.seft::getG('config/SYS/Mal')."\n".'Content-Type:text/html;charset=utf-8');}}

 

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
11 Best PHP URL Shortener Scripts (Free and Premium)11 Best PHP URL Shortener Scripts (Free and Premium)Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Introduction to the Instagram APIIntroduction to the Instagram APIMar 02, 2025 am 09:32 AM

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, ReactBuild a React App With a Laravel Back End: Part 2, ReactMar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation SurveyAnnouncement of 2025 PHP Situation SurveyMar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software