Nette\Mail\SmtpMailer::connect PHP Méthode

connect() protected méthode

Connects and authenticates to SMTP server.
protected connect ( ) : void
Résultat void
    protected function connect()
    {
        $this->connection = @stream_socket_client(($this->secure === 'ssl' ? 'ssl://' : '') . $this->host . ':' . $this->port, $errno, $error, $this->timeout, STREAM_CLIENT_CONNECT, $this->context);
        if (!$this->connection) {
            throw new SmtpException($error, $errno);
        }
        stream_set_timeout($this->connection, $this->timeout, 0);
        $this->read();
        // greeting
        $self = isset($_SERVER['HTTP_HOST']) && preg_match('#^[\\w.-]+\\z#', $_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
        $this->write("EHLO {$self}");
        $ehloResponse = $this->read();
        if ((int) $ehloResponse !== 250) {
            $this->write("HELO {$self}", 250);
        }
        if ($this->secure === 'tls') {
            $this->write('STARTTLS', 220);
            if (!stream_socket_enable_crypto($this->connection, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
                throw new SmtpException('Unable to connect via TLS.');
            }
            $this->write("EHLO {$self}", 250);
        }
        if ($this->username != NULL && $this->password != NULL) {
            $authMechanisms = [];
            if (preg_match('~^250[ -]AUTH (.*)$~im', $ehloResponse, $matches)) {
                $authMechanisms = explode(' ', trim($matches[1]));
            }
            if (in_array('PLAIN', $authMechanisms, TRUE)) {
                $credentials = $this->username . "" . $this->username . "" . $this->password;
                $this->write('AUTH PLAIN ' . base64_encode($credentials), 235, 'PLAIN credentials');
            } else {
                $this->write('AUTH LOGIN', 334);
                $this->write(base64_encode($this->username), 334, 'username');
                $this->write(base64_encode($this->password), 235, 'password');
            }
        }
    }