|
25 | 25 | #include "ext/date/php_date.h" |
26 | 26 | #include "zend_smart_str.h" |
27 | 27 |
|
| 28 | +#ifdef HAVE_SYS_WAIT_H |
| 29 | +#include <sys/wait.h> |
| 30 | +#endif |
| 31 | + |
28 | 32 | #ifdef HAVE_SYSEXITS_H |
29 | 33 | # include <sysexits.h> |
30 | 34 | #endif |
@@ -417,6 +421,7 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co |
417 | 421 | #endif |
418 | 422 | FILE *sendmail; |
419 | 423 | int ret; |
| 424 | + int wstatus; |
420 | 425 | char *sendmail_path = INI_STR("sendmail_path"); |
421 | 426 | char *sendmail_cmd = NULL; |
422 | 427 | char *mail_log = INI_STR("mail.log"); |
@@ -557,26 +562,44 @@ PHPAPI int php_mail(const char *to, const char *subject, const char *message, co |
557 | 562 | fprintf(sendmail, "%s%s", hdr, line_sep); |
558 | 563 | } |
559 | 564 | fprintf(sendmail, "%s%s%s", line_sep, message, line_sep); |
| 565 | +#ifdef PHP_WIN32 |
560 | 566 | ret = pclose(sendmail); |
561 | | - |
562 | 567 | #if PHP_SIGCHILD |
563 | 568 | if (sig_handler) { |
564 | 569 | signal(SIGCHLD, sig_handler); |
565 | 570 | } |
566 | 571 | #endif |
567 | | - |
568 | | -#ifdef PHP_WIN32 |
569 | | - if (ret == -1) |
570 | 572 | #else |
| 573 | + wstatus = pclose(sendmail); |
| 574 | +#if PHP_SIGCHILD |
| 575 | + if (sig_handler) { |
| 576 | + signal(SIGCHLD, sig_handler); |
| 577 | + } |
| 578 | +#endif |
| 579 | + /* Determine the wait(2) exit status */ |
| 580 | + if (wstatus == -1) { |
| 581 | + php_error_docref(NULL, E_WARNING, "Sendmail pclose failed %d (%s)", errno, strerror(errno)); |
| 582 | + MAIL_RET(0); |
| 583 | + } else if (WIFSIGNALED(wstatus)) { |
| 584 | + php_error_docref(NULL, E_WARNING, "Sendmail killed by signal %d (%s)", WTERMSIG(wstatus), strsignal(WTERMSIG(wstatus))); |
| 585 | + MAIL_RET(0); |
| 586 | + } else if (!WIFEXITED(wstatus)) { |
| 587 | + php_error_docref(NULL, E_WARNING, "Sendmail did not exit"); |
| 588 | + MAIL_RET(0); |
| 589 | + } else { |
| 590 | + ret = WEXITSTATUS(wstatus); |
| 591 | + } |
| 592 | +#endif |
| 593 | + |
571 | 594 | #if defined(EX_TEMPFAIL) |
572 | 595 | if ((ret != EX_OK)&&(ret != EX_TEMPFAIL)) |
573 | 596 | #elif defined(EX_OK) |
574 | 597 | if (ret != EX_OK) |
575 | 598 | #else |
576 | 599 | if (ret != 0) |
577 | | -#endif |
578 | 600 | #endif |
579 | 601 | { |
| 602 | + php_error_docref(NULL, E_WARNING, "Sendmail exited with non-zero exit code %d", ret); |
580 | 603 | MAIL_RET(0); |
581 | 604 | } else { |
582 | 605 | MAIL_RET(1); |
|
0 commit comments