/** * Connect to SMTP Server * * @return void * @throws SocketException */ protected function _connect() { $this->_generateSocket(); if (!$this->_socket->connect()) { throw new SocketException(__d('cake_dev', 'Unable to connect to SMTP server.')); } $this->_smtpSend(null, '220'); if (isset($this->_config['client'])) { $host = $this->_config['client']; } elseif ($httpHost = env('HTTP_HOST')) { list($host) = explode(':', $httpHost); } else { $host = 'localhost'; } try { $this->_smtpSend("EHLO {$host}", '250'); if ($this->_config['tls']) { $this->_smtpSend("STARTTLS", '220'); $this->_socket->enableCrypto('tls'); $this->_smtpSend("EHLO {$host}", '250'); } } catch (SocketException $e) { if ($this->_config['tls']) { throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection or trying to connect to non TLS SMTP server using TLS.')); } try { $this->_smtpSend("HELO {$host}", '250'); } catch (SocketException $e2) { throw new SocketException(__d('cake_dev', 'SMTP server did not accept the connection.')); } } }