| @@ 1581-1661 (lines=81) @@ | ||
| 1578 | $hosts = explode(';', $this->Host); |
|
| 1579 | $lastexception = null; |
|
| 1580 | ||
| 1581 | foreach ($hosts as $hostentry) { |
|
| 1582 | $hostinfo = array(); |
|
| 1583 | if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) { |
|
| 1584 | // Not a valid host entry |
|
| 1585 | continue; |
|
| 1586 | } |
|
| 1587 | // $hostinfo[2]: optional ssl or tls prefix |
|
| 1588 | // $hostinfo[3]: the hostname |
|
| 1589 | // $hostinfo[4]: optional port number |
|
| 1590 | // The host string prefix can temporarily override the current setting for SMTPSecure |
|
| 1591 | // If it's not specified, the default value is used |
|
| 1592 | $prefix = ''; |
|
| 1593 | $secure = $this->SMTPSecure; |
|
| 1594 | $tls = ($this->SMTPSecure == 'tls'); |
|
| 1595 | if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) { |
|
| 1596 | $prefix = 'ssl://'; |
|
| 1597 | $tls = false; // Can't have SSL and TLS at the same time |
|
| 1598 | $secure = 'ssl'; |
|
| 1599 | } elseif ($hostinfo[2] == 'tls') { |
|
| 1600 | $tls = true; |
|
| 1601 | // tls doesn't use a prefix |
|
| 1602 | $secure = 'tls'; |
|
| 1603 | } |
|
| 1604 | //Do we need the OpenSSL extension? |
|
| 1605 | $sslext = defined('OPENSSL_ALGO_SHA1'); |
|
| 1606 | if ('tls' === $secure or 'ssl' === $secure) { |
|
| 1607 | //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled |
|
| 1608 | if (!$sslext) { |
|
| 1609 | throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL); |
|
| 1610 | } |
|
| 1611 | } |
|
| 1612 | $host = $hostinfo[3]; |
|
| 1613 | $port = $this->Port; |
|
| 1614 | $tport = (integer)$hostinfo[4]; |
|
| 1615 | if ($tport > 0 and $tport < 65536) { |
|
| 1616 | $port = $tport; |
|
| 1617 | } |
|
| 1618 | if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) { |
|
| 1619 | try { |
|
| 1620 | if ($this->Helo) { |
|
| 1621 | $hello = $this->Helo; |
|
| 1622 | } else { |
|
| 1623 | $hello = $this->serverHostname(); |
|
| 1624 | } |
|
| 1625 | $this->smtp->hello($hello); |
|
| 1626 | //Automatically enable TLS encryption if: |
|
| 1627 | // * it's not disabled |
|
| 1628 | // * we have openssl extension |
|
| 1629 | // * we are not already using SSL |
|
| 1630 | // * the server offers STARTTLS |
|
| 1631 | if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) { |
|
| 1632 | $tls = true; |
|
| 1633 | } |
|
| 1634 | if ($tls) { |
|
| 1635 | if (!$this->smtp->startTLS()) { |
|
| 1636 | throw new phpmailerException($this->lang('connect_host')); |
|
| 1637 | } |
|
| 1638 | // We must resend EHLO after TLS negotiation |
|
| 1639 | $this->smtp->hello($hello); |
|
| 1640 | } |
|
| 1641 | if ($this->SMTPAuth) { |
|
| 1642 | if (!$this->smtp->authenticate( |
|
| 1643 | $this->Username, |
|
| 1644 | $this->Password, |
|
| 1645 | $this->AuthType, |
|
| 1646 | $this->Realm, |
|
| 1647 | $this->Workstation |
|
| 1648 | ) |
|
| 1649 | ) { |
|
| 1650 | throw new phpmailerException($this->lang('authenticate')); |
|
| 1651 | } |
|
| 1652 | } |
|
| 1653 | return true; |
|
| 1654 | } catch (phpmailerException $exc) { |
|
| 1655 | $lastexception = $exc; |
|
| 1656 | $this->edebug($exc->getMessage()); |
|
| 1657 | // We must have connected, but then failed TLS or Auth, so close connection nicely |
|
| 1658 | $this->smtp->quit(); |
|
| 1659 | } |
|
| 1660 | } |
|
| 1661 | } |
|
| 1662 | // If we get here, all connection attempts have failed, so close connection hard |
|
| 1663 | $this->smtp->close(); |
|
| 1664 | // As we've caught all exceptions, just report whatever the last one was |
|
| @@ 107-188 (lines=82) @@ | ||
| 104 | $hosts = explode(';', $this->Host); |
|
| 105 | $lastexception = null; |
|
| 106 | ||
| 107 | foreach ($hosts as $hostentry) { |
|
| 108 | $hostinfo = array(); |
|
| 109 | if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) { |
|
| 110 | // Not a valid host entry |
|
| 111 | continue; |
|
| 112 | } |
|
| 113 | // $hostinfo[2]: optional ssl or tls prefix |
|
| 114 | // $hostinfo[3]: the hostname |
|
| 115 | // $hostinfo[4]: optional port number |
|
| 116 | // The host string prefix can temporarily override the current setting for SMTPSecure |
|
| 117 | // If it's not specified, the default value is used |
|
| 118 | $prefix = ''; |
|
| 119 | $secure = $this->SMTPSecure; |
|
| 120 | $tls = ($this->SMTPSecure == 'tls'); |
|
| 121 | if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) { |
|
| 122 | $prefix = 'ssl://'; |
|
| 123 | $tls = false; // Can't have SSL and TLS at the same time |
|
| 124 | $secure = 'ssl'; |
|
| 125 | } elseif ($hostinfo[2] == 'tls') { |
|
| 126 | $tls = true; |
|
| 127 | // tls doesn't use a prefix |
|
| 128 | $secure = 'tls'; |
|
| 129 | } |
|
| 130 | //Do we need the OpenSSL extension? |
|
| 131 | $sslext = defined('OPENSSL_ALGO_SHA1'); |
|
| 132 | if ('tls' === $secure or 'ssl' === $secure) { |
|
| 133 | //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled |
|
| 134 | if (!$sslext) { |
|
| 135 | throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL); |
|
| 136 | } |
|
| 137 | } |
|
| 138 | $host = $hostinfo[3]; |
|
| 139 | $port = $this->Port; |
|
| 140 | $tport = (integer)$hostinfo[4]; |
|
| 141 | if ($tport > 0 and $tport < 65536) { |
|
| 142 | $port = $tport; |
|
| 143 | } |
|
| 144 | if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) { |
|
| 145 | try { |
|
| 146 | if ($this->Helo) { |
|
| 147 | $hello = $this->Helo; |
|
| 148 | } else { |
|
| 149 | $hello = $this->serverHostname(); |
|
| 150 | } |
|
| 151 | $this->smtp->hello($hello); |
|
| 152 | //Automatically enable TLS encryption if: |
|
| 153 | // * it's not disabled |
|
| 154 | // * we have openssl extension |
|
| 155 | // * we are not already using SSL |
|
| 156 | // * the server offers STARTTLS |
|
| 157 | if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) { |
|
| 158 | $tls = true; |
|
| 159 | } |
|
| 160 | if ($tls) { |
|
| 161 | if (!$this->smtp->startTLS()) { |
|
| 162 | throw new phpmailerException($this->lang('connect_host')); |
|
| 163 | } |
|
| 164 | // We must resend HELO after tls negotiation |
|
| 165 | $this->smtp->hello($hello); |
|
| 166 | } |
|
| 167 | if ($this->SMTPAuth) { |
|
| 168 | if (!$this->smtp->authenticate( |
|
| 169 | $this->Username, |
|
| 170 | $this->Password, |
|
| 171 | $this->AuthType, |
|
| 172 | $this->Realm, |
|
| 173 | $this->Workstation, |
|
| 174 | $this->oauth |
|
| 175 | ) |
|
| 176 | ) { |
|
| 177 | throw new phpmailerException($this->lang('authenticate')); |
|
| 178 | } |
|
| 179 | } |
|
| 180 | return true; |
|
| 181 | } catch (phpmailerException $exc) { |
|
| 182 | $lastexception = $exc; |
|
| 183 | $this->edebug($exc->getMessage()); |
|
| 184 | // We must have connected, but then failed TLS or Auth, so close connection nicely |
|
| 185 | $this->smtp->quit(); |
|
| 186 | } |
|
| 187 | } |
|
| 188 | } |
|
| 189 | // If we get here, all connection attempts have failed, so close connection hard |
|
| 190 | $this->smtp->close(); |
|
| 191 | // As we've caught all exceptions, just report whatever the last one was |
|