diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 3c732f84bf4..eef112a00e2 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -1030,7 +1030,7 @@ class CMailFile $res = false; if (!empty($conf->global->MAIN_MAIL_DEBUG)) { - $this->save_dump_mail_in_err('Mail with topic '.$this->subject); + $this->save_dump_mail_in_err('Mail smtp error '.$smtperrorcode.' with topic '.$this->subject); } } } @@ -1289,13 +1289,25 @@ class CMailFile global $dolibarr_main_data_root; if (@is_writeable($dolibarr_main_data_root)) { // Avoid fatal error on fopen with open_basedir - // Add message to dolibarr_mail.log + $srcfile = $dolibarr_main_data_root."/dolibarr_mail.log"; + + // Add message to dolibarr_mail.log. We do not use dol_syslog() on purpose, + // to be sure to write into dolibarr_mail.log if ($message) { - dol_syslog($message, LOG_DEBUG, 0, '_mail'); + // Test constant SYSLOG_FILE_NO_ERROR (should stay a constant defined with define('SYSLOG_FILE_NO_ERROR',1); + if (defined('SYSLOG_FILE_NO_ERROR')) { + $filefd = @fopen($srcfile, 'a+'); + } else { + $filefd = fopen($srcfile, 'a+'); + } + if ($filefd) { + fwrite($filefd, $message."\n"); + fclose($filefd); + dolChmod($srcfile); + } } // Move dolibarr_mail.log into a dolibarr_mail.err or dolibarr_mail.date.err - $srcfile = $dolibarr_main_data_root."/dolibarr_mail.log"; if (getDolGlobalString('MAIN_MAIL_DEBUG_ERR_WITH_DATE')) { $destfile = $dolibarr_main_data_root."/dolibarr_mail.".dol_print_date(dol_now(), 'dayhourlog', 'gmt').".err"; } else { diff --git a/htdocs/core/modules/syslog/mod_syslog_file.php b/htdocs/core/modules/syslog/mod_syslog_file.php index 73ebc0d1d90..116e49487f9 100644 --- a/htdocs/core/modules/syslog/mod_syslog_file.php +++ b/htdocs/core/modules/syslog/mod_syslog_file.php @@ -125,7 +125,7 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface } } - return $suffixinfilename ?preg_replace('/\.log$/i', $suffixinfilename.'.log', $tmp) : $tmp; + return $suffixinfilename ? preg_replace('/\.log$/i', $suffixinfilename.'.log', $tmp) : $tmp; } /**