Skip to content

Commit

Permalink
Alter the way that SMTP host lists are parsed, fixes PHPMailer#112
Browse files Browse the repository at this point in the history
  • Loading branch information
Synchro committed Sep 23, 2013
1 parent c92b5bc commit accd948
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Add connection events and new level 3 to debug output options
* Chinese language update (Thanks to @binaryoung)
* Allow custom Mailer types (thanks to @michield)
* Cope with spaces around SMTP host specs

## Version 5.2.7 (September 12th 2013)
* Add Ukranian translation from @Krezalis
Expand Down
13 changes: 3 additions & 10 deletions class.phpmailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -1248,17 +1248,10 @@ public function smtpConnect($options = array())
$lastexception = null;

foreach ($hosts as $hostentry) {
$hostinfo = array();
$host = $hostentry;
$host = trim($hostentry);
$port = $this->Port;
if (preg_match(
'/^(.+):([0-9]+)$/',
$hostentry,
$hostinfo
)
) { //If $hostentry contains 'address:port', override default
$host = $hostinfo[1];
$port = $hostinfo[2];
if (strpos($host, ':') !== false) {
list($host, $port) = explode(':', $host);
}
if ($this->smtp->connect(($ssl ? 'ssl://' : '') . $host, $port, $this->Timeout, $options)) {
try {
Expand Down
3 changes: 3 additions & 0 deletions test/phpmailerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,9 @@ public function testSmtpConnect()
$this->Mail->Host = "localhost:12345;10.10.10.10:54321;" . $_REQUEST['mail_host'];
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP multi-connect failed');
$this->Mail->smtpClose();
$this->Mail->Host = " localhost:12345 ; " . $_REQUEST['mail_host'] . ' ';
$this->assertTrue($this->Mail->smtpConnect(), 'SMTP hosts with stray spaces failed');
$this->Mail->smtpClose();
$this->Mail->Host = $_REQUEST['mail_host'];
//Need to pick a harmless option so as not cause problems of its own! socket:bind doesn't work with Travis-CI
$this->assertTrue(
Expand Down

0 comments on commit accd948

Please sign in to comment.