PHPMailer\PHPMailer

POP3::connectpublicWP 1.0

Connect to a POP3 server.

Method of the class: POP3{}

No Hooks.

Returns

true|false.

Usage

$POP3 = new POP3();
$POP3->connect( $host, $port, $tval );
$host(string) (required)
.
$port(int|true|false)
.
Default: false
$tval(int)
.
Default: 30

POP3::connect() code WP 6.9

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(function () {
        call_user_func_array([$this, 'catchWarning'], func_get_args());
    });

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

    //Connect to the POP3 server
    $errno = 0;
    $errstr = '';
    $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;
}