You are here

public function DrupalPHPMailer::SmtpSend in PHPMailer 7.3

Same name and namespace in other branches
  1. 5.2 includes/phpmailer.class.inc \DrupalPHPMailer::SmtpSend()
  2. 6.3 includes/phpmailer.class.inc \DrupalPHPMailer::SmtpSend()
  3. 6.2 includes/phpmailer.class.inc \DrupalPHPMailer::SmtpSend()
  4. 7.4 includes/phpmailer.class.inc \DrupalPHPMailer::SmtpSend()

Send mail via SMTP.

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

File

includes/phpmailer.class.inc, line 103
Implements the base PHPMailer for Drupal class.

Class

DrupalPHPMailer
Class for implementing the PHPMailer library in Drupal.

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 (variable_get('smtp_debug_log', 0)) {
        watchdog('phpmailer', 'Output of communication with SMTP server:<br /><pre>!output</pre>', array(
          '!output' => print_r($this->drupalDebugOutput, TRUE),
        ), WATCHDOG_DEBUG);
      }
    }
    ob_end_clean();
  }

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

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