PHPMailer\PHPMailer\POP3::connect PHP Method

connect() public method

Connect to a POP3 server.
public connect ( string $host, integer | boolean $port = false, integer $tval = 30 ) : boolean
$host string
$port integer | boolean
$tval integer
return boolean
    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 = $this->POP3_PORT;
        }
        //  connect to the POP3 server
        $this->pop_conn = fsockopen($host, $port, $errno, $errstr, $tval);
        //  Timeout (seconds)
        //  Restore the error handler
        restore_error_handler();
        //  Did we connect?
        if (false === $this->pop_conn) {
            //  It would appear not...
            $this->setError(['error' => "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;
    }