@@ -286,34 +286,35 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
286
286
return val; \
287
287
288
288
if (mail_log && * mail_log ) {
289
- char * tmp ;
290
- time_t curtime ;
291
- size_t l ;
292
- zend_string * date_str ;
289
+ char * logline ;
293
290
294
- time (& curtime );
295
- date_str = php_format_date ("d-M-Y H:i:s e" , 13 , curtime , 1 );
296
-
297
- l = spprintf (& tmp , 0 , "[%s] mail() on [%s:%d]: To: %s -- Headers: %s -- Subject: %s\n" , ZSTR_VAL (date_str ), zend_get_executed_filename (), zend_get_executed_lineno (), to , hdr ? hdr : "" , subject );
298
-
299
- zend_string_free (date_str );
291
+ spprintf (& logline , 0 , "mail() on [%s:%d]: To: %s -- Headers: %s -- Subject: %s" , zend_get_executed_filename (), zend_get_executed_lineno (), to , hdr ? hdr : "" , subject );
300
292
301
293
if (hdr ) {
302
- php_mail_log_crlf_to_spaces (tmp );
294
+ php_mail_log_crlf_to_spaces (logline );
303
295
}
304
296
305
297
if (!strcmp (mail_log , "syslog" )) {
306
- /* Drop the final space when logging to syslog. */
307
- tmp [l - 1 ] = 0 ;
308
- php_mail_log_to_syslog (tmp );
309
- }
310
- else {
311
- /* Convert the final space to a newline when logging to file. */
312
- tmp [l - 1 ] = '\n' ;
313
- php_mail_log_to_file (mail_log , tmp , l );
298
+ php_mail_log_to_syslog (logline );
299
+ } else {
300
+ /* Add date when logging to file */
301
+ char * tmp ;
302
+ time_t curtime ;
303
+ zend_string * date_str ;
304
+ size_t len ;
305
+
306
+
307
+ time (& curtime );
308
+ date_str = php_format_date ("d-M-Y H:i:s e" , 13 , curtime , 1 );
309
+ len = spprintf (& tmp , 0 , "[%s] %s%s" , date_str -> val , logline , PHP_EOL );
310
+
311
+ php_mail_log_to_file (mail_log , tmp , len );
312
+
313
+ zend_string_free (date_str );
314
+ efree (tmp );
314
315
}
315
316
316
- efree (tmp );
317
+ efree (logline );
317
318
}
318
319
319
320
if (PG (mail_x_header )) {
0 commit comments