You are here

function PHPMailer::SmtpConnect in SMTP Authentication Support 5

Same name and namespace in other branches
  1. 7.2 smtp.phpmailer.inc \PHPMailer::SmtpConnect()
  2. 7 smtp.phpmailer.inc \PHPMailer::SmtpConnect()

Initiates a connection to an SMTP server. Returns false if the operation failed. @access private

Return value

bool

1 call to PHPMailer::SmtpConnect()
PHPMailer::SmtpSend in ./smtp.module
Sends mail via SMTP using PhpSMTP (Author: Chris Ryan). Returns bool. Returns false if there is a bad MAIL FROM, RCPT, or DATA input. @access private

File

./smtp.module, line 975
Enables drupal to send email directly to an SMTP server using authentication. Uses the PHPMailer class by Brent R. Matzelle.

Class

PHPMailer
PHPMailer - PHP email transport class @package PHPMailer @author Brent R. Matzelle @copyright 2001 - 2003 Brent R. Matzelle

Code

function SmtpConnect() {
  if ($this->smtp == NULL) {
    $this->smtp = new SMTP();
  }
  $this->smtp->protocol = $this->Protocol;

  //Custom line added for ssl support.
  $this->smtp->do_debug = $this->SMTPDebug;
  $hosts = explode(";", $this->Host);
  $index = 0;
  $connection = $this->smtp
    ->Connected();

  // Retry while there is no connection
  while ($index < count($hosts) && $connection == false) {
    if (strstr($hosts[$index], ":")) {
      list($host, $port) = explode(":", $hosts[$index]);
    }
    else {
      $host = $hosts[$index];
      $port = $this->Port;
    }
    if ($this->smtp
      ->Connect($host, $port, $this->Timeout)) {
      if ($this->Helo != '') {
        $this->smtp
          ->Hello($this->Helo);
      }
      else {
        $this->smtp
          ->Hello($this
          ->ServerHostname());
      }
      if ($this->SMTPAuth) {
        if (!$this->smtp
          ->Authenticate($this->Username, $this->Password)) {
          $this
            ->SetError($this
            ->Lang("authenticate"));
          $this->smtp
            ->Reset();
          $connection = false;
        }
      }
      $connection = true;
    }
    $index++;
  }
  if (!$connection) {
    $this
      ->SetError($this
      ->Lang("connect_host"));
  }
  return $connection;
}