Skip to content

Commit 6a75612

Browse files
lollipopmanbukka
authored andcommitted
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 c5e7490 commit 6a75612

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
@@ -604,13 +604,16 @@ PHPAPI bool php_mail(const char *to, const char *subject, const char *message, c
604604
#endif
605605
/* Determine the wait(2) exit status */
606606
if (wstatus == -1) {
607+
php_error_docref(NULL, E_WARNING, "Sendmail pclose failed %d (%s)", errno, strerror(errno));
607608
MAIL_RET(false);
608609
} else if (WIFSIGNALED(wstatus)) {
610+
php_error_docref(NULL, E_WARNING, "Sendmail killed by signal %d (%s)", WTERMSIG(wstatus), strsignal(WTERMSIG(wstatus)));
609611
MAIL_RET(false);
610612
} else {
611613
if (WIFEXITED(wstatus)) {
612614
ret = WEXITSTATUS(wstatus);
613615
} else {
616+
php_error_docref(NULL, E_WARNING, "Sendmail did not exit");
614617
MAIL_RET(false);
615618
}
616619
}
@@ -624,6 +627,7 @@ PHPAPI bool php_mail(const char *to, const char *subject, const char *message, c
624627
if (ret != 0)
625628
#endif
626629
{
630+
php_error_docref(NULL, E_WARNING, "Sendmail exited with non-zero exit code %d", ret);
627631
MAIL_RET(false);
628632
} else {
629633
MAIL_RET(true);

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)