Skip to content

Commit

Permalink
Throw error only when hosts to try are exhausted.
Browse files Browse the repository at this point in the history
  • Loading branch information
NanoCaiordo committed May 13, 2013
1 parent c2b084f commit d4b0414
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions class.phpmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1074,18 +1074,15 @@ public function SmtpConnect() {
$this->smtp->Debugoutput = $this->Debugoutput;
$this->smtp->do_verp = $this->do_verp;
$hosts = explode(';', $this->Host);
$index = 0;
$connection = $this->smtp->Connected();

// Retry while there is no connection
try {
while($index < count($hosts) && !$connection) {
$hostinfo = array();
if (preg_match('/^(.+):([0-9]+)$/', $hosts[$index], $hostinfo)) {
for ($i=0,$c=count($hosts); $i<$c; ++$i) {
try {
if (preg_match('/^(.+):([0-9]+)$/', $hosts[$i], $hostinfo)) {
$host = $hostinfo[1];
$port = $hostinfo[2];
} else {
$host = $hosts[$index];
$host = $hosts[$i];
$port = $this->Port;
}

Expand All @@ -1106,25 +1103,23 @@ public function SmtpConnect() {
$this->smtp->Hello($hello);
}

$connection = true;
if ($this->SMTPAuth) {
if (!$this->smtp->Authenticate($this->Username, $this->Password, $this->AuthType, $this->Realm, $this->Workstation)) {
throw new phpmailerException($this->Lang('authenticate'));
}
}
}
$index++;
if (!$connection) {
} else {
throw new phpmailerException($this->Lang('connect_host'));
}
}
} catch (phpmailerException $e) {
$this->smtp->Reset();
if ($this->exceptions) {
throw $e;
return true;
} catch (phpmailerException $e) {
$this->smtp->Reset();
if ($i==$c-1 && $this->exceptions) {
throw $e;
}
}
}
return true;
return false;
}

/**
Expand Down

0 comments on commit d4b0414

Please sign in to comment.