private function connection()
    {
        $url = $this->url;

        if ($this->secure === true) {
            $url = 'ssl://' . $this->url;
        }

        $this->sock = fsockopen($url, $this->port, $errno, $errstr, $this->timeout);

        if ($this->sock == null) {
            throw new SocketException('Impossible to get connected to ' . $this->url . ':' . $this->port, E_USER_ERROR);
        }

        stream_set_timeout($this->sock, $this->timeout, 0);
        $code = $this->read();

        $host = isset($_SERVER['HTTP_HOST']) &&
        preg_match('/^[\w.-]+\z/', $_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';

        if ($code == 220) {
            $code = $this->write('EHLO ' . $host, 250, 'HELO');
            if ($code != 250) {
                $this->write('EHLO ' . $host, 250, 'HELO');
            }
        }

        if ($this->tls === true) {
            $this->write('STARTTLS', 220);

            $secured = @stream_socket_enable_crypto($this->sock, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);

            if (!$secured) {
                throw new ErrorException('Can not secure your connection with tls', E_ERROR);
            }
        }

        if ($this->username !== null && $this->password !== null) {
            $this->write('AUTH LOGIN', 334);
            $this->write(base64_encode($this->username), 334, 'username');
            $this->write(base64_encode($this->password), 235, 'password');
        }
    }
private function connection()
    {
        $url = $this->url;

        if ($this->secure === true) {
            $url = 'ssl://' . $this->url;
        }

        $this->sock = fsockopen($url, $this->port, $errno, $errstr, $this->timeout);

        if ($this->sock == null) {
            throw new SocketException('Impossible to get connected to ' . $this->url . ':' . $this->port, E_USER_ERROR);
        }

        stream_set_timeout($this->sock, $this->timeout, 0);
        $code = $this->read();

        $host = isset($_SERVER['HTTP_HOST']) &&
        preg_match('/^[\w.-]+\z/', $_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';

        if ($code == 220) {
            $code = $this->write('EHLO ' . $host, 250, 'HELO');
            if ($code != 250) {
                $this->write('EHLO ' . $host, 250, 'HELO');
            }
        }

        if ($this->tls === true) {
            $this->write('STARTTLS', 220);

            $secured = @stream_socket_enable_crypto($this->sock, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);

            if (!$secured) {
                throw new ErrorException('Can not secure your connection with tls', E_ERROR);
            }
        }

        if ($this->username !== null && $this->password !== null) {
            $this->write('AUTH LOGIN', 334);
            $this->write(base64_encode($this->username), 334, 'username');
            $this->write(base64_encode($this->password), 235, 'password');
        }
    }
private function connection ( ) { $ url = $ this -> url ; if ( $ this -> secure === true ) { $ url = 'ssl://' . $ this -> url ; } $ this -> sock = fsockopen ( $ url , $ this -> port , $ errno , $ errstr , $ this -> timeout ) ; if ( $ this -> sock == null ) { throw new SocketException ( 'Impossible to get connected to ' . $ this -> url . ':' . $ this -> port , E_USER_ERROR ) ; } stream_set_timeout ( $ this -> sock , $ this -> timeout , 0 ) ; $ code = $ this -> read ( ) ; $ host = isset ( $ _SERVER [ 'HTTP_HOST' ] ) && preg_match ( '/^[\w.-]+\z/' , $ _SERVER [ 'HTTP_HOST' ] ) ? $ _SERVER [ 'HTTP_HOST' ] : 'localhost' ; if ( $ code == 220 ) { $ code = $ this -> write ( 'EHLO ' . $ host , 250 , 'HELO' ) ; if ( $ code != 250 ) { $ this -> write ( 'EHLO ' . $ host , 250 , 'HELO' ) ; } } if ( $ this -> tls === true ) { $ this -> write ( 'STARTTLS' , 220 ) ; $ secured = @ stream_socket_enable_crypto ( $ this -> sock , true , STREAM_CRYPTO_METHOD_TLS_CLIENT ) ; if ( ! $ secured ) { throw new ErrorException ( 'Can not secure your connection with tls' , E_ERROR ) ; } } if ( $ this -> username !== null && $ this -> password !== null ) { $ this -> write ( 'AUTH LOGIN' , 334 ) ; $ this -> write ( base64_encode ( $ this -> username ) , 334 , 'username' ) ; $ this -> write ( base64_encode ( $ this -> password ) , 235 , 'password' ) ; } }
Connect to an SMTP server

@throws ErrorException
@throws SocketException | SmtpException
Connect to an SMTP server