public function connect($host, $port = false, $tval = 30)
    {
        //  Are we already connected?
        if ($this->connected) {
            return true;
        }

        //On Windows this will raise a PHP Warning error if the hostname doesn't exist.
        //Rather than suppress it with @fsockopen, capture it cleanly instead
        set_error_handler([$this, 'catchWarning']);

        if (false === $port) {
            $port = static::DEFAULT_PORT;
        }

        //  connect to the POP3 server
        $this->pop_conn = fsockopen(
            $host, //  POP3 Host
            $port, //  Port #
            $errno, //  Error Number
            $errstr, //  Error Message
            $tval
        ); //  Timeout (seconds)
        //  Restore the error handler
        restore_error_handler();

        //  Did we connect?
        if (false === $this->pop_conn) {
            //  It would appear not...
            $this->setError(
                "Failed to connect to server $host on port $port. errno: $errno; errstr: $errstr"
            );

            return false;
        }

        //  Increase the stream time-out
        stream_set_timeout($this->pop_conn, $tval, 0);

        //  Get the POP3 server response
        $pop3_response = $this->getResponse();
        //  Check for the +OK
        if ($this->checkResponse($pop3_response)) {
            //  The connection is established and the POP3 server is talking
            $this->connected = true;

            return true;
        }

        return false;
    }
public function connect($host, $port = false, $tval = 30)
    {
        //  Are we already connected?
        if ($this->connected) {
            return true;
        }

        //On Windows this will raise a PHP Warning error if the hostname doesn't exist.
        //Rather than suppress it with @fsockopen, capture it cleanly instead
        set_error_handler([$this, 'catchWarning']);

        if (false === $port) {
            $port = static::DEFAULT_PORT;
        }

        //  connect to the POP3 server
        $this->pop_conn = fsockopen(
            $host, //  POP3 Host
            $port, //  Port #
            $errno, //  Error Number
            $errstr, //  Error Message
            $tval
        ); //  Timeout (seconds)
        //  Restore the error handler
        restore_error_handler();

        //  Did we connect?
        if (false === $this->pop_conn) {
            //  It would appear not...
            $this->setError(
                "Failed to connect to server $host on port $port. errno: $errno; errstr: $errstr"
            );

            return false;
        }

        //  Increase the stream time-out
        stream_set_timeout($this->pop_conn, $tval, 0);

        //  Get the POP3 server response
        $pop3_response = $this->getResponse();
        //  Check for the +OK
        if ($this->checkResponse($pop3_response)) {
            //  The connection is established and the POP3 server is talking
            $this->connected = true;

            return true;
        }

        return false;
    }
public function connect ( $ host , $ port = false , $ tval = 30 ) { //  Are we already connected? if ( $ this -> connected ) { return true ; } //On Windows this will raise a PHP Warning error if the hostname doesn't exist. //Rather than suppress it with @fsockopen, capture it cleanly instead set_error_handler ( [ $ this , 'catchWarning' ] ) ; if ( false === $ port ) { $ port = static :: DEFAULT_PORT ; } //  connect to the POP3 server $ this -> pop_conn = fsockopen ( $ host , //  POP3 Host $ port , //  Port # $ errno , //  Error Number $ errstr , //  Error Message $ tval ) ; //  Timeout (seconds) //  Restore the error handler restore_error_handler ( ) ; //  Did we connect? if ( false === $ this -> pop_conn ) { //  It would appear not... $ this -> setError ( "Failed to connect to server $host on port $port. errno: $errno; errstr: $errstr" ) ; return false ; } //  Increase the stream time-out stream_set_timeout ( $ this -> pop_conn , $ tval , 0 ) ; //  Get the POP3 server response $ pop3_response = $ this -> getResponse ( ) ; //  Check for the +OK if ( $ this -> checkResponse ( $ pop3_response ) ) { //  The connection is established and the POP3 server is talking $ this -> connected = true ; return true ; } return false ; }
Connect to a POP3 server.

@param string   $host
@param int|bool $port
@param int      $tval

@return bool
Connect to a POP3 server .