Commit cb01a8b1cfa for php.net
commit cb01a8b1cfa5adb25e0ba2fd193353f7a4686b32
Author: Shivam Mathur <shivam_jpr@hotmail.com>
Date: Wed Aug 5 16:04:33 2026 +0530
Fix Windows mail handling regressions (#23060)
diff --git a/ext/standard/mail.c b/ext/standard/mail.c
index 6aac0d364cf..6d85d06d1f6 100644
--- a/ext/standard/mail.c
+++ b/ext/standard/mail.c
@@ -528,7 +528,7 @@ PHPAPI bool php_mail(const char *to, const char *subject, const char *message, c
MAIL_RET(false);
}
- if (!sendmail_path) {
+ if (!(sendmail_path && sendmail_path[0] != '\0')) {
#ifdef PHP_WIN32
int tsm_err;
char *tsm_errmsg = NULL;
@@ -702,7 +702,7 @@ PHP_MINFO_FUNCTION(mail)
const char *sendmail_path = zend_ini_string_literal("sendmail_path");
#ifdef PHP_WIN32
- if (!sendmail_path) {
+ if (!(sendmail_path && sendmail_path[0] != '\0')) {
php_info_print_table_row(2, "Internal Sendmail Support for Windows", "enabled");
} else {
php_info_print_table_row(2, "Path to sendmail", sendmail_path);
diff --git a/win32/sendmail.c b/win32/sendmail.c
index 0160838054d..cd44e87fc79 100644
--- a/win32/sendmail.c
+++ b/win32/sendmail.c
@@ -216,8 +216,9 @@ PHPAPI int TSendMail(const char *host, int *error, char **error_message,
}
/* Fall back to sendmail_from php.ini setting */
- if (zend_ini_string_literal("sendmail_from")) {
- RPath = estrdup(zend_ini_string_literal("sendmail_from"));
+ const char *sendmail_from = zend_ini_string_literal("sendmail_from");
+ if (sendmail_from && sendmail_from[0] != '\0') {
+ RPath = estrdup(sendmail_from);
} else if (headers_lc) {
int found = 0;
const char *lookup = ZSTR_VAL(headers_lc);
@@ -505,14 +506,6 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, const
efree(tempMailTo);
}
- if (!Post("DATA\r\n")) {
- return (FAILED_TO_SEND);
- }
- if ((res = Ack(&server_response)) != SUCCESS) {
- SMTP_ERROR_RESPONSE(server_response);
- return (res);
- }
-
/* Send mail to all Bcc rcpt's
This is basically a rip of the Cc code above.
Just don't forget to remove the Bcc: from the header afterwards. */
@@ -579,8 +572,7 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, const
which would look like "\r\n\r\n". */
stripped_header = zend_string_concat2(ZSTR_VAL(headers), header_length_prior_to_bcc, pos2 + 2, strlen(pos2) - 2);
} else {
- stripped_header = zend_string_truncate(headers, header_length_prior_to_bcc, false);
- ZSTR_VAL(stripped_header)[ZSTR_LEN(stripped_header)] = '\0';
+ stripped_header = zend_string_init(ZSTR_VAL(headers), header_length_prior_to_bcc, false);
}
} else {
/* Simplify the code that we create a copy of stripped_header no matter if
@@ -589,6 +581,14 @@ static int SendText(char *RPath, const char *Subject, const char *mailTo, const
}
}
+ if (!Post("DATA\r\n")) {
+ return (FAILED_TO_SEND);
+ }
+ if ((res = Ack(&server_response)) != SUCCESS) {
+ SMTP_ERROR_RESPONSE(server_response);
+ return (res);
+ }
+
/* send message header */
bool PostHeaderIsSuccessful = false;
if (Subject == NULL) {