phpmailer write debug inside log file

Viewed 16

I tried to create a new log file if there is a phpmailer error. But the file is not created. I check my directory (777). Do you have an idea ? Thank you

       if (DEBUG_EMAIL == 'true'){
              $this->phpMail->SMTPDebug = $this->debug_level; //2
              $this->phpMail->Debugoutput = function($str, $level) {
                $filename = CLICSHOPPING::BASE_DIR . 'Work/Log/phpmail_error-' . date('Ymd') . '.log';
                $data = date('Y-m-d H:i:s') . "\t" . "\t$level\t$str\n";
                $flags =  FILE_APPEND | LOCK_EX;

                file_put_contents($filename, $data, $flags);
                };

//              $this->phpMail->SMTPDebug = SMTP::DEBUG_SERVER;
            }
1 Answers

Double check all your values, don't assume they are what you think they are. For example what is in CLICSHOPPING::BASE_DIR? Also, it's usual for directory env vars to not have a trailing slash, so you may be missing one when you append Work/... to it. Try this:

$filename = CLICSHOPPING::BASE_DIR . '/Work/Log/phpmail_error-' . date('Ymd') . '.log';
            $data = date('Y-m-d H:i:s') . "\t" . "\t$level\t$str\n";
Related