Skip to content

Commit fd2c27c

Browse files
author
Shane Caraveo
committed
Enable using an external mailer under windows.
1. this depends on the patch to fix tsrm I sent to dev 2. this provides backwards compatibility, as long as sendmail_path in the ini file is empty, the old internal mailer will be used, once sendmail_path is defined, the external sendmail program will be used. I tested with indigomail from www.indigostar.com, which provides the same command line interface as sendmail no linux.
1 parent 69d129b commit fd2c27c

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

ext/standard/mail.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ PHP_FUNCTION(mail)
130130
} else {
131131
RETVAL_FALSE;
132132
}
133-
efree (extra_cmd);
133+
if (extra_cmd) efree (extra_cmd);
134134
}
135135
/* }}} */
136136

@@ -140,21 +140,23 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
140140
{
141141
#ifdef PHP_WIN32
142142
int tsm_err;
143-
#else
143+
#endif
144144
FILE *sendmail;
145145
int ret;
146146
char *sendmail_path = INI_STR("sendmail_path");
147147
char *sendmail_cmd = NULL;
148-
#endif
149148

149+
if (!sendmail_path) {
150150
#ifdef PHP_WIN32
151-
if (TSendMail(INI_STR("SMTP"), &tsm_err, headers, subject, to, message) != SUCCESS){
152-
php_error(E_WARNING, GetSMErrorText(tsm_err));
153-
return 0;
154-
}
151+
/* handle old style win smtp sending */
152+
if (TSendMail(INI_STR("SMTP"), &tsm_err, headers, subject, to, message) != SUCCESS){
153+
php_error(E_WARNING, GetSMErrorText(tsm_err));
154+
return 0;
155+
}
156+
return 1;
155157
#else
156-
if (!sendmail_path) {
157158
return 0;
159+
#endif
158160
}
159161
if (extra_cmd != NULL) {
160162
sendmail_cmd = emalloc (strlen (sendmail_path) + strlen (extra_cmd) + 2);
@@ -165,7 +167,11 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
165167
sendmail_cmd = sendmail_path;
166168
}
167169

170+
#ifdef PHP_WIN32
171+
sendmail = popen(sendmail_cmd, "wb");
172+
#else
168173
sendmail = popen(sendmail_cmd, "w");
174+
#endif
169175
if (extra_cmd != NULL)
170176
efree (sendmail_cmd);
171177

@@ -177,11 +183,16 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
177183
}
178184
fprintf(sendmail, "\n%s\n", message);
179185
ret = pclose(sendmail);
186+
#ifdef PHP_WIN32
187+
if (ret == -1)
188+
#else
180189
#if defined(EX_TEMPFAIL)
181-
if ((ret != EX_OK)&&(ret != EX_TEMPFAIL)) {
190+
if ((ret != EX_OK)&&(ret != EX_TEMPFAIL))
182191
#else
183-
if (ret != EX_OK) {
192+
if (ret != EX_OK)
193+
#endif
184194
#endif
195+
{
185196
return 0;
186197
} else {
187198
return 1;
@@ -190,7 +201,6 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
190201
php_error(E_WARNING, "Could not execute mail delivery program");
191202
return 0;
192203
}
193-
#endif
194204
return 1;
195205
}
196206
/* }}} */
@@ -200,10 +210,12 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
200210
PHP_MINFO_FUNCTION(mail)
201211
{
202212
#ifdef PHP_WIN32
213+
char *sendmail_path = INI_STR("sendmail_path");
214+
if (!sendmail_path)
203215
php_info_print_table_row(2, "Internal Sendmail Support for Windows 4", "enabled");
204-
#else
205-
php_info_print_table_row(2, "Path to sendmail", INI_STR("sendmail_path") );
216+
else
206217
#endif
218+
php_info_print_table_row(2, "Path to sendmail", INI_STR("sendmail_path") );
207219
}
208220
/* }}} */
209221

0 commit comments

Comments
 (0)