You are here

public function DrupalPHPMailer::SmtpSend in PHPMailer 8.3

Send mail via SMTP.

Wrapper around PHPMailer::SmtpSend() with exception handling.

File

src/Plugin/Mail/DrupalPHPMailer.php, line 109

Class

DrupalPHPMailer
Implements the base PHPMailer class for the Drupal MailInterface.

Namespace

Drupal\phpmailer\Plugin\Mail

Code

public function SmtpSend($header, $body) {
  if ($this->SMTPDebug) {

    // Clear possibly previously captured debug output.
    $this->drupalDebugOutput = '';
    ob_start();
  }
  try {
    $result = parent::SmtpSend($header, $body);

    // Close connection when not using SMTP keep-alive.
    if (!$this->SMTPKeepAlive) {
      $this
        ->SmtpClose();
    }
  } catch (phpmailerException $exception) {
  }
  if ($this->SMTPDebug) {
    if ($this->drupalDebug && ($this->drupalDebugOutput = ob_get_contents())) {
      drupal_set_message($this->drupalDebugOutput);
      if (\Drupal::config('phpmailer.settings')
        ->get('smtp_debug_log', 0)) {
        \Drupal::logger('phpmailer')
          ->debug('Output of communication with SMTP server:<br /><pre>{output}</pre>', [
          'output' => print_r($this->drupalDebugOutput, TRUE),
        ]);
      }
    }
    ob_end_clean();
  }

  // Reinitialize properties.
  $this
    ->Reset();
  if (isset($exception)) {

    // Pass exception to caller.
    throw $exception;
  }
  return $result;
}