基本上我在我的网站上有一个页面,我希望每次运行脚本时都会在电子邮件中发送任何php erorrs,warnings等.
编辑:这必须是放在页面上的代码,而不是对php_ini的编辑或类似的东西.
编辑2:这需要捕获所有错误并在脚本末尾的一封电子邮件中发送所有错误
你需要设置一个错误处理程序并注册一个关闭函数来进行邮件发送.在一个非常简单的示例中,可能看起来像这样:
<?php
$__errors = array();
function my_error_handler($code, $message, $file, $line) {
global $__errors;
$__errors[] = sprintf('"%s" (%s line %s)', $message, $file, $line);
}
set_error_handler( 'my_error_handler', E_ALL );
function send_error_log() {
global $__errors;
if ( count( $__errors ) > 0 ) {
foreach ( $__errors as $error ) {
$body . $error . "\n";
}
mail( 'to@example.com', 'error log', $body );
}
}
register_shutdown_function( 'send_error_log' );
?>
Run Code Online (Sandbox Code Playgroud)