Skip to content

Commit fe28fc3

Browse files
committed
mail: add logging on errors
Prior to this commit the exit code of the sendmail command, called by the mail function was lost, since the mail function only returns true or false. Add additional logging to the mail function to capture the exit code when the sendmail command fails.
1 parent 57508c8 commit fe28fc3

File tree

6 files changed

+18
-5
lines changed

6 files changed

+18
-5
lines changed

ext/standard/mail.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,13 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
579579
#endif
580580
/* Determine the wait(2) exit status */
581581
if (wstatus == -1) {
582+
php_error_docref(NULL, E_WARNING, "Sendmail pclose failed %d (%s)", errno, strerror(errno));
582583
MAIL_RET(0);
583584
} else if (WIFSIGNALED(wstatus)) {
585+
php_error_docref(NULL, E_WARNING, "Sendmail killed by signal %d (%s)", WTERMSIG(wstatus), strsignal(WTERMSIG(wstatus)));
584586
MAIL_RET(0);
585587
} else if (!WIFEXITED(wstatus)) {
588+
php_error_docref(NULL, E_WARNING, "Sendmail did not exit");
586589
MAIL_RET(0);
587590
} else {
588591
ret = WEXITSTATUS(wstatus);
@@ -597,6 +600,7 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
597600
if (ret != 0)
598601
#endif
599602
{
603+
php_error_docref(NULL, E_WARNING, "Sendmail exited with non-zero exit code %d", ret);
600604
MAIL_RET(0);
601605
} else {
602606
MAIL_RET(1);

ext/standard/tests/mail/gh10990.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ $from = '[email protected]';
1313
$headers = ['From' => &$from];
1414
var_dump(mail('[email protected]', 'Test', 'Test', $headers));
1515
?>
16-
--EXPECT--
16+
--EXPECTF--
17+
Warning: mail(): Sendmail exited with non-zero exit code 127 in %sgh10990.php on line %d
1718
bool(false)

ext/standard/tests/mail/mail_basic5.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ $message = 'A Message';
2020
echo "-- failure --\n";
2121
var_dump( mail($to, $subject, $message) );
2222
?>
23-
--EXPECT--
23+
--EXPECTF--
2424
*** Testing mail() : basic functionality ***
2525
-- failure --
26+
27+
Warning: mail(): Sendmail exited with non-zero exit code 1 in %smail_basic5.php on line %d
2628
bool(false)

ext/standard/tests/mail/mail_variation1.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ $subject = 'Test Subject';
1717
$message = 'A Message';
1818
var_dump( mail($to, $subject, $message) );
1919
?>
20-
--EXPECT--
20+
--EXPECTF--
2121
*** Testing mail() : variation ***
22+
23+
Warning: mail(): Sendmail exited with non-zero exit code 127 in %smail_variation1.php on line %d
2224
bool(false)

ext/standard/tests/mail/mail_variation4.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ $subject = 'Test Subject';
1717
$message = 'A Message';
1818
var_dump( mail($to, $subject, $message) );
1919
?>
20-
--EXPECT--
20+
--EXPECTF--
2121
*** Testing mail() : variation ***
22+
23+
Warning: mail(): Sendmail killed by signal %d (%s) in %smail_variation4.php on line %d
2224
bool(false)

ext/standard/tests/mail/mail_variation5.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ $subject = 'Test Subject';
1717
$message = 'A Message';
1818
var_dump( mail($to, $subject, $message) );
1919
?>
20-
--EXPECT--
20+
--EXPECTF--
2121
*** Testing mail() : variation ***
22+
23+
Warning: mail(): Sendmail exited with non-zero exit code 123 in %smail_variation5.php on line %d
2224
bool(false)

0 commit comments

Comments
 (0)