Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions ext/standard/mail.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
#endif
FILE *sendmail;
int ret;
int wstatus;
char *sendmail_path = INI_STR("sendmail_path");
char *sendmail_cmd = NULL;
char *mail_log = INI_STR("mail.log");
Expand Down Expand Up @@ -557,26 +558,44 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co
fprintf(sendmail, "%s%s", hdr, line_sep);
}
fprintf(sendmail, "%s%s%s", line_sep, message, line_sep);
#ifdef PHP_WIN32
ret = pclose(sendmail);

#if PHP_SIGCHILD
if (sig_handler) {
signal(SIGCHLD, sig_handler);
}
#endif

#ifdef PHP_WIN32
if (ret == -1)
#else
wstatus = pclose(sendmail);
#if PHP_SIGCHILD
if (sig_handler) {
signal(SIGCHLD, sig_handler);
}
#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(ret)) {
php_error_docref(NULL, E_WARNING, "Sendmail did not exit");
MAIL_RET(0);
} else {
ret = WEXITSTATUS(wstatus);
}
#endif

#if defined(EX_TEMPFAIL)
if ((ret != EX_OK)&&(ret != EX_TEMPFAIL))
#elif defined(EX_OK)
if (ret != EX_OK)
#else
if (ret != 0)
#endif
#endif
{
php_error_docref(NULL, E_WARNING, "Sendmail exited with non-zero exit code %d", ret);
MAIL_RET(0);
} else {
MAIL_RET(1);
Expand Down
3 changes: 2 additions & 1 deletion ext/standard/tests/mail/gh10990.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ $from = '[email protected]';
$headers = ['From' => &$from];
var_dump(mail('[email protected]', 'Test', 'Test', $headers));
?>
--EXPECT--
--EXPECTF--
Warning: mail(): Sendmail exited with non-zero exit code 127 in %sgh10990.php on line %d
bool(false)
4 changes: 3 additions & 1 deletion ext/standard/tests/mail/mail_basic5.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ $message = 'A Message';
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)
4 changes: 3 additions & 1 deletion ext/standard/tests/mail/mail_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ $subject = 'Test Subject';
$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)
22 changes: 22 additions & 0 deletions ext/standard/tests/mail/mail_variation3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
Test mail() function : variation sendmail temp fail
--INI--
sendmail_path=exit 75
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
echo "*** Testing mail() : variation ***\n";

// Initialise all required variables
$to = '[email protected]';
$subject = 'Test Subject';
$message = 'A Message';
var_dump( mail($to, $subject, $message) );
?>
--EXPECT--
*** Testing mail() : variation ***
bool(true)
24 changes: 24 additions & 0 deletions ext/standard/tests/mail/mail_variation4.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
Test mail() function : variation sigkill
--INI--
sendmail_path="kill \$\$"
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) == "WIN")
die("skip Won't run on Windows");
?>
--FILE--
<?php
echo "*** Testing mail() : variation ***\n";

// Initialise all required variables
$to = '[email protected]';
$subject = 'Test Subject';
$message = 'A Message';
var_dump( mail($to, $subject, $message) );
?>
--EXPECTF--
*** Testing mail() : variation ***

Warning: mail(): Sendmail killed by signal 15 (Terminated) in %smail_variation4.php on line %d
bool(false)
Loading