Backport of upstream commit 6a75612

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.

--- a/ext/standard/mail.c
+++ b/ext/standard/mail.c
@@ -539,13 +539,16 @@
 #endif
 		/* Determine the wait(2) exit status */
 		if (wstatus == -1) {
+			php_error_docref(NULL, E_WARNING, "Sendmail pclose failed %d (%s)", errno, strerror(errno));
 			MAIL_RET(0);
 		} else if (WIFSIGNALED(wstatus)) {
+			php_error_docref(NULL, E_WARNING, "Sendmail killed by signal %d (%s)", WTERMSIG(wstatus), strsignal(WTERMSIG(wstatus)));
 			MAIL_RET(0);
 		} else {
 			if (WIFEXITED(wstatus)) {
 				ret = WEXITSTATUS(wstatus);
 			} else {
+				php_error_docref(NULL, E_WARNING, "Sendmail did not exit");
 				MAIL_RET(0);
 			}
 		}
@@ -559,6 +562,7 @@
 		if (ret != 0)
 #endif
 		{
+			php_error_docref(NULL, E_WARNING, "Sendmail exited with non-zero exit code %d", ret);
 			MAIL_RET(0);
 		} else {
 			MAIL_RET(1);
--- a/ext/standard/tests/mail/gh10990.phpt
+++ b/ext/standard/tests/mail/gh10990.phpt
@@ -13,5 +13,6 @@
 $headers = ['From' => &$from];
 var_dump(mail('test@example.com', 'Test', 'Test', $headers));
 ?>
---EXPECT--
+--EXPECTF--
+Warning: mail(): Sendmail exited with non-zero exit code 127 in %sgh10990.php on line %d
 bool(false)
--- a/ext/standard/tests/mail/mail_basic5.phpt
+++ b/ext/standard/tests/mail/mail_basic5.phpt
@@ -20,7 +20,9 @@
 echo "-- failure --\n";
 var_dump( mail($to, $subject, $message) );
 ?>
---EXPECT--
+--EXPECTF--
 *** Testing mail() : basic functionality ***
 -- failure --
+
+Warning: mail(): Sendmail exited with non-zero exit code 1 in %smail_basic5.php on line %d
 bool(false)
--- a/ext/standard/tests/mail/mail_variation1.phpt
+++ b/ext/standard/tests/mail/mail_variation1.phpt
@@ -17,6 +17,8 @@
 $message = 'A Message';
 var_dump( mail($to, $subject, $message) );
 ?>
---EXPECT--
+--EXPECTF--
 *** Testing mail() : variation ***
+
+Warning: mail(): Sendmail exited with non-zero exit code 127 in %smail_variation1.php on line %d
 bool(false)
--- a/ext/standard/tests/mail/mail_variation4.phpt
+++ b/ext/standard/tests/mail/mail_variation4.phpt
@@ -17,6 +17,8 @@
 $message = 'A Message';
 var_dump(mail($to, $subject, $message));
 ?>
---EXPECT--
+--EXPECTF--
 *** Testing mail() : variation ***
+
+Warning: mail(): Sendmail killed by signal %d (%s) in %smail_variation4.php on line %d
 bool(false)
--- a/ext/standard/tests/mail/mail_variation5.phpt
+++ b/ext/standard/tests/mail/mail_variation5.phpt
@@ -17,6 +17,8 @@
 $message = 'A Message';
 var_dump(mail($to, $subject, $message));
 ?>
---EXPECT--
+--EXPECTF--
 *** Testing mail() : variation ***
+
+Warning: mail(): Sendmail exited with non-zero exit code 123 in %smail_variation5.php on line %d
 bool(false)
