function SMTP::edebug

5.x SMTP.php protected SMTP::edebug($str, $level = 0)

Output debugging info via a user-selected method.

Parameters

string $str Debug string to output:

int $level The debug level of this message; see DEBUG_* constants:

See also

SMTP::$Debugoutput

SMTP::$do_debug

File

inc/PHPMailer/src/SMTP.php, line 230

Class

SMTP
PHPMailer RFC821 SMTP email transport class. Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.

Code

protected function edebug($str, $level = 0) {
  if ($level > $this->do_debug) {
    return;
  }
  //Is this a PSR-3 logger?
  if ($this->Debugoutput instanceof \Psr\Log\LoggerInterface) {
    $this->Debugoutput->debug($str);

    return;
  }
  //Avoid clash with built-in function names
  if (!in_array($this->Debugoutput, ['error_log' 'html' 'echo']) and is_callable($this->Debugoutput)) {
    call_user_func($this->Debugoutput, $str, $level);

    return;
  }
  switch ($this->Debugoutput) {
    case 'error_log':
      //Don't output, just log
      error_log($str);
      break;
    case 'html':
      //Cleans up output a bit for a better looking, HTML-safe output
      echo gmdate('Y-m-d H:i:s'), ' ', htmlentities(preg_replace('/[\r\n]+/', '', $str), ENT_QUOTES, 'UTF-8'), "<br>\n";
      break;
    case 'echo':
    default:
      //Normalize line breaks
      $str = preg_replace('/\r\n|\r/ms', "\n", $str);
      echo gmdate('Y-m-d H:i:s'), "\t", 
      //Trim trailing space
      trim(
      //Indent for readability, except for trailing break
      str_replace("\n", "\n                   \t                  ", trim($str))), "\n";
  }
}