Skip to content

Commit 4a3bf25

Browse files
mjlstrojny
authored andcommitted
Add a timestamp to the mail log.
This patch is loosely based on the one in bug #52126 but instead of using a UNIX timestamp it uses the date format also being used by error_log et al.
1 parent 853ef3c commit 4a3bf25

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ext/standard/mail.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
#include <stdlib.h>
2222
#include <ctype.h>
2323
#include <stdio.h>
24+
#include <time.h>
2425
#include "php.h"
2526
#include "ext/standard/info.h"
2627
#include "ext/standard/php_string.h"
2728
#include "ext/standard/basic_functions.h"
29+
#include "ext/date/php_date.h"
2830

2931
#if HAVE_SYSEXITS_H
3032
#include <sysexits.h>
@@ -246,8 +248,15 @@ PHPAPI int php_mail(char *to, char *subject, char *message, char *headers, char
246248
return val; \
247249

248250
if (mail_log && *mail_log) {
249-
char *tmp;
250-
int l = spprintf(&tmp, 0, "mail() on [%s:%d]: To: %s -- Headers: %s\n", zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : "");
251+
char *tmp, *date_str;
252+
time_t curtime;
253+
254+
time(&curtime);
255+
date_str = php_format_date("d-M-Y H:i:s e", 13, curtime, 1 TSRMLS_CC);
256+
257+
int l = spprintf(&tmp, 0, "[%s] mail() on [%s:%d]: To: %s -- Headers: %s\n", date_str, zend_get_executed_filename(TSRMLS_C), zend_get_executed_lineno(TSRMLS_C), to, hdr ? hdr : "");
258+
259+
efree(date_str);
251260

252261
if (hdr) {
253262
php_mail_log_crlf_to_spaces(tmp);

0 commit comments

Comments
 (0)