xref: /PHP-8.0/ext/standard/tests/mail/gh7875.phpt (revision 4c35d644)
1--TEST--
2GH-7875 (mails are sent even if failure to log throws exception)
3--INI--
4sendmail_path={MAIL:{PWD}/gh7875.mail.out}
5mail.log={PWD}/gh7875.mail.log
6--SKIPIF--
7<?php
8if (PHP_OS_FAMILY !== "Windows") {
9    if (!extension_loaded('posix')) die('skip POSIX extension not loaded');
10    if (posix_geteuid() == 0) die('skip Cannot run test as root.');
11}
12?>
13--FILE--
14<?php
15function exception_error_handler($severity, $message, $file, $line) {
16    if (!(error_reporting() & $severity)) {
17        return;
18    }
19    throw new ErrorException($message, 0, $severity, $file, $line);
20}
21set_error_handler("exception_error_handler");
22
23touch(__DIR__ . "/gh7875.mail.log");
24chmod(__DIR__ . "/gh7875.mail.log", 0444);
25
26try {
27	mail('recipient@example.com', 'Subject', 'Body', []);
28	echo 'Not Reached';
29} catch (\Exception $e) {
30	echo $e->getMessage(), PHP_EOL;
31    var_dump(file_exists(__DIR__ . "/gh7875.mail.out"));
32}
33?>
34--CLEAN--
35<?php
36@chmod(__DIR__ . "/gh7875.mail.log", 0644);
37@unlink(__DIR__ . "/gh7875.mail.log");
38@unlink(__DIR__ . "/gh7875.mail.out");
39?>
40--EXPECTF--
41mail(%s): Failed to open stream: Permission denied
42bool(false)
43