@@ -130,7 +130,7 @@ PHP_FUNCTION(mail)
130
130
} else {
131
131
RETVAL_FALSE ;
132
132
}
133
- efree (extra_cmd );
133
+ if ( extra_cmd ) efree (extra_cmd );
134
134
}
135
135
/* }}} */
136
136
@@ -140,21 +140,23 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
140
140
{
141
141
#ifdef PHP_WIN32
142
142
int tsm_err ;
143
- #else
143
+ #endif
144
144
FILE * sendmail ;
145
145
int ret ;
146
146
char * sendmail_path = INI_STR ("sendmail_path" );
147
147
char * sendmail_cmd = NULL ;
148
- #endif
149
148
149
+ if (!sendmail_path ) {
150
150
#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 ;
155
157
#else
156
- if (!sendmail_path ) {
157
158
return 0 ;
159
+ #endif
158
160
}
159
161
if (extra_cmd != NULL ) {
160
162
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
165
167
sendmail_cmd = sendmail_path ;
166
168
}
167
169
170
+ #ifdef PHP_WIN32
171
+ sendmail = popen (sendmail_cmd , "wb" );
172
+ #else
168
173
sendmail = popen (sendmail_cmd , "w" );
174
+ #endif
169
175
if (extra_cmd != NULL )
170
176
efree (sendmail_cmd );
171
177
@@ -177,11 +183,16 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
177
183
}
178
184
fprintf (sendmail , "\n%s\n" , message );
179
185
ret = pclose (sendmail );
186
+ #ifdef PHP_WIN32
187
+ if (ret == -1 )
188
+ #else
180
189
#if defined(EX_TEMPFAIL )
181
- if ((ret != EX_OK )&& (ret != EX_TEMPFAIL )) {
190
+ if ((ret != EX_OK )&& (ret != EX_TEMPFAIL ))
182
191
#else
183
- if (ret != EX_OK ) {
192
+ if (ret != EX_OK )
193
+ #endif
184
194
#endif
195
+ {
185
196
return 0 ;
186
197
} else {
187
198
return 1 ;
@@ -190,7 +201,6 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
190
201
php_error (E_WARNING , "Could not execute mail delivery program" );
191
202
return 0 ;
192
203
}
193
- #endif
194
204
return 1 ;
195
205
}
196
206
/* }}} */
@@ -200,10 +210,12 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
200
210
PHP_MINFO_FUNCTION (mail )
201
211
{
202
212
#ifdef PHP_WIN32
213
+ char * sendmail_path = INI_STR ("sendmail_path" );
214
+ if (!sendmail_path )
203
215
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
206
217
#endif
218
+ php_info_print_table_row (2 , "Path to sendmail" , INI_STR ("sendmail_path" ) );
207
219
}
208
220
/* }}} */
209
221
0 commit comments