From accd948dada841919e3b769c494870fd1f86db34 Mon Sep 17 00:00:00 2001 From: Synchro Date: Mon, 23 Sep 2013 09:12:02 +0200 Subject: [PATCH] Alter the way that SMTP host lists are parsed, fixes #112 --- changelog.md | 1 + class.phpmailer.php | 13 +++---------- test/phpmailerTest.php | 3 +++ 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/changelog.md b/changelog.md index bdc2ed2f1..06ec7d84b 100644 --- a/changelog.md +++ b/changelog.md @@ -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 diff --git a/class.phpmailer.php b/class.phpmailer.php index e8e16f664..fa0f9369b 100644 --- a/class.phpmailer.php +++ b/class.phpmailer.php @@ -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 { diff --git a/test/phpmailerTest.php b/test/phpmailerTest.php index 1b4cf1ab5..9b24b5483 100644 --- a/test/phpmailerTest.php +++ b/test/phpmailerTest.php @@ -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(