| @@ 1541-1621 (lines=81) @@ | ||
| 1538 | $hosts = explode(';', $this->Host); |
|
| 1539 | $lastexception = null; |
|
| 1540 | ||
| 1541 | foreach ($hosts as $hostentry) { |
|
| 1542 | $hostinfo = array(); |
|
| 1543 | if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) { |
|
| 1544 | // Not a valid host entry |
|
| 1545 | continue; |
|
| 1546 | } |
|
| 1547 | // $hostinfo[2]: optional ssl or tls prefix |
|
| 1548 | // $hostinfo[3]: the hostname |
|
| 1549 | // $hostinfo[4]: optional port number |
|
| 1550 | // The host string prefix can temporarily override the current setting for SMTPSecure |
|
| 1551 | // If it's not specified, the default value is used |
|
| 1552 | $prefix = ''; |
|
| 1553 | $secure = $this->SMTPSecure; |
|
| 1554 | $tls = ($this->SMTPSecure == 'tls'); |
|
| 1555 | if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) { |
|
| 1556 | $prefix = 'ssl://'; |
|
| 1557 | $tls = false; // Can't have SSL and TLS at the same time |
|
| 1558 | $secure = 'ssl'; |
|
| 1559 | } elseif ($hostinfo[2] == 'tls') { |
|
| 1560 | $tls = true; |
|
| 1561 | // tls doesn't use a prefix |
|
| 1562 | $secure = 'tls'; |
|
| 1563 | } |
|
| 1564 | //Do we need the OpenSSL extension? |
|
| 1565 | $sslext = defined('OPENSSL_ALGO_SHA1'); |
|
| 1566 | if ('tls' === $secure or 'ssl' === $secure) { |
|
| 1567 | //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled |
|
| 1568 | if (!$sslext) { |
|
| 1569 | throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL); |
|
| 1570 | } |
|
| 1571 | } |
|
| 1572 | $host = $hostinfo[3]; |
|
| 1573 | $port = $this->Port; |
|
| 1574 | $tport = (integer)$hostinfo[4]; |
|
| 1575 | if ($tport > 0 and $tport < 65536) { |
|
| 1576 | $port = $tport; |
|
| 1577 | } |
|
| 1578 | if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) { |
|
| 1579 | try { |
|
| 1580 | if ($this->Helo) { |
|
| 1581 | $hello = $this->Helo; |
|
| 1582 | } else { |
|
| 1583 | $hello = $this->serverHostname(); |
|
| 1584 | } |
|
| 1585 | $this->smtp->hello($hello); |
|
| 1586 | //Automatically enable TLS encryption if: |
|
| 1587 | // * it's not disabled |
|
| 1588 | // * we have openssl extension |
|
| 1589 | // * we are not already using SSL |
|
| 1590 | // * the server offers STARTTLS |
|
| 1591 | if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) { |
|
| 1592 | $tls = true; |
|
| 1593 | } |
|
| 1594 | if ($tls) { |
|
| 1595 | if (!$this->smtp->startTLS()) { |
|
| 1596 | throw new phpmailerException($this->lang('connect_host')); |
|
| 1597 | } |
|
| 1598 | // We must resend HELO after tls negotiation |
|
| 1599 | $this->smtp->hello($hello); |
|
| 1600 | } |
|
| 1601 | if ($this->SMTPAuth) { |
|
| 1602 | if (!$this->smtp->authenticate( |
|
| 1603 | $this->Username, |
|
| 1604 | $this->Password, |
|
| 1605 | $this->AuthType, |
|
| 1606 | $this->Realm, |
|
| 1607 | $this->Workstation |
|
| 1608 | ) |
|
| 1609 | ) { |
|
| 1610 | throw new phpmailerException($this->lang('authenticate')); |
|
| 1611 | } |
|
| 1612 | } |
|
| 1613 | return true; |
|
| 1614 | } catch (phpmailerException $exc) { |
|
| 1615 | $lastexception = $exc; |
|
| 1616 | $this->edebug($exc->getMessage()); |
|
| 1617 | // We must have connected, but then failed TLS or Auth, so close connection nicely |
|
| 1618 | $this->smtp->quit(); |
|
| 1619 | } |
|
| 1620 | } |
|
| 1621 | } |
|
| 1622 | // If we get here, all connection attempts have failed, so close connection hard |
|
| 1623 | $this->smtp->close(); |
|
| 1624 | // As we've caught all exceptions, just report whatever the last one was |
|
| @@ 106-187 (lines=82) @@ | ||
| 103 | $hosts = explode(';', $this->Host); |
|
| 104 | $lastexception = null; |
|
| 105 | ||
| 106 | foreach ($hosts as $hostentry) { |
|
| 107 | $hostinfo = array(); |
|
| 108 | if (!preg_match('/^((ssl|tls):\/\/)*([a-zA-Z0-9\.-]*):?([0-9]*)$/', trim($hostentry), $hostinfo)) { |
|
| 109 | // Not a valid host entry |
|
| 110 | continue; |
|
| 111 | } |
|
| 112 | // $hostinfo[2]: optional ssl or tls prefix |
|
| 113 | // $hostinfo[3]: the hostname |
|
| 114 | // $hostinfo[4]: optional port number |
|
| 115 | // The host string prefix can temporarily override the current setting for SMTPSecure |
|
| 116 | // If it's not specified, the default value is used |
|
| 117 | $prefix = ''; |
|
| 118 | $secure = $this->SMTPSecure; |
|
| 119 | $tls = ($this->SMTPSecure == 'tls'); |
|
| 120 | if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) { |
|
| 121 | $prefix = 'ssl://'; |
|
| 122 | $tls = false; // Can't have SSL and TLS at the same time |
|
| 123 | $secure = 'ssl'; |
|
| 124 | } elseif ($hostinfo[2] == 'tls') { |
|
| 125 | $tls = true; |
|
| 126 | // tls doesn't use a prefix |
|
| 127 | $secure = 'tls'; |
|
| 128 | } |
|
| 129 | //Do we need the OpenSSL extension? |
|
| 130 | $sslext = defined('OPENSSL_ALGO_SHA1'); |
|
| 131 | if ('tls' === $secure or 'ssl' === $secure) { |
|
| 132 | //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled |
|
| 133 | if (!$sslext) { |
|
| 134 | throw new phpmailerException($this->lang('extension_missing').'openssl', self::STOP_CRITICAL); |
|
| 135 | } |
|
| 136 | } |
|
| 137 | $host = $hostinfo[3]; |
|
| 138 | $port = $this->Port; |
|
| 139 | $tport = (integer)$hostinfo[4]; |
|
| 140 | if ($tport > 0 and $tport < 65536) { |
|
| 141 | $port = $tport; |
|
| 142 | } |
|
| 143 | if ($this->smtp->connect($prefix . $host, $port, $this->Timeout, $options)) { |
|
| 144 | try { |
|
| 145 | if ($this->Helo) { |
|
| 146 | $hello = $this->Helo; |
|
| 147 | } else { |
|
| 148 | $hello = $this->serverHostname(); |
|
| 149 | } |
|
| 150 | $this->smtp->hello($hello); |
|
| 151 | //Automatically enable TLS encryption if: |
|
| 152 | // * it's not disabled |
|
| 153 | // * we have openssl extension |
|
| 154 | // * we are not already using SSL |
|
| 155 | // * the server offers STARTTLS |
|
| 156 | if ($this->SMTPAutoTLS and $sslext and $secure != 'ssl' and $this->smtp->getServerExt('STARTTLS')) { |
|
| 157 | $tls = true; |
|
| 158 | } |
|
| 159 | if ($tls) { |
|
| 160 | if (!$this->smtp->startTLS()) { |
|
| 161 | throw new phpmailerException($this->lang('connect_host')); |
|
| 162 | } |
|
| 163 | // We must resend HELO after tls negotiation |
|
| 164 | $this->smtp->hello($hello); |
|
| 165 | } |
|
| 166 | if ($this->SMTPAuth) { |
|
| 167 | if (!$this->smtp->authenticate( |
|
| 168 | $this->Username, |
|
| 169 | $this->Password, |
|
| 170 | $this->AuthType, |
|
| 171 | $this->Realm, |
|
| 172 | $this->Workstation, |
|
| 173 | $this->oauth |
|
| 174 | ) |
|
| 175 | ) { |
|
| 176 | throw new phpmailerException($this->lang('authenticate')); |
|
| 177 | } |
|
| 178 | } |
|
| 179 | return true; |
|
| 180 | } catch (phpmailerException $exc) { |
|
| 181 | $lastexception = $exc; |
|
| 182 | $this->edebug($exc->getMessage()); |
|
| 183 | // We must have connected, but then failed TLS or Auth, so close connection nicely |
|
| 184 | $this->smtp->quit(); |
|
| 185 | } |
|
| 186 | } |
|
| 187 | } |
|
| 188 | // If we get here, all connection attempts have failed, so close connection hard |
|
| 189 | $this->smtp->close(); |
|
| 190 | // As we've caught all exceptions, just report whatever the last one was |
|