POP3::Connect PHP Method

Connect() public method

Connect to the POP3 server
public Connect ( string $host, integer $port = false, integer $tval = 30 ) : boolean
$host string
$port integer
$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 supress it with @fsockopen, let's capture it cleanly instead
        */
        set_error_handler(array(&$this, 'catchWarning'));
        //  Connect to the POP3 server
        $this->pop_conn = fsockopen($host, $port, $errno, $errstr, $tval);
        //  Timeout (seconds)
        //  Restore the error handler
        restore_error_handler();
        //  Does the Error Log now contain anything?
        if ($this->error && $this->do_debug >= 1) {
            $this->displayErrors();
        }
        //  Did we connect?
        if ($this->pop_conn == false) {
            //  It would appear not...
            $this->error = array('error' => "Failed to connect to server {$host} on port {$port}", 'errno' => $errno, 'errstr' => $errstr);
            if ($this->do_debug >= 1) {
                $this->displayErrors();
            }
            return false;
        }
        //  Increase the stream time-out
        //  Check for PHP 4.3.0 or later
        if (version_compare(phpversion(), '5.0.0', 'ge')) {
            stream_set_timeout($this->pop_conn, $tval, 0);
        } else {
            //  Does not work on Windows
            if (substr(PHP_OS, 0, 3) !== 'WIN') {
                socket_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;
        }
    }

Usage Example

Esempio n. 1
0
         echo "<span class=\"error\">SMTP:  'SMTP Server' field not filled in.</span><br />";
     } else {
         if ($_REQUEST["from"] == "") {
             echo "<span class=\"error\">SMTP:  'Default E-mail Address' field not filled in.</span><br />";
         } else {
             if ($_REQUEST["to"] == "") {
                 echo "<span class=\"error\">SMTP:  'Send To' field not filled in.</span><br />";
             }
         }
     }
 }
 $pop3valid = false;
 if ($pop3server != "" && $_REQUEST["user"] != "" && $_REQUEST["pass"] != "") {
     $pop3options = array("server" => $pop3server, "port" => $pop3port, "secure" => $pop3port == 995);
     $temppop3 = new POP3();
     $result = $temppop3->Connect($_REQUEST["user"], $_REQUEST["pass"], $pop3options);
     if (!$result["success"]) {
         echo "<span class=\"error\">Failed to connect to the POP3 server.  " . htmlspecialchars($result["error"]) . (isset($result["info"]) ? " (" . htmlspecialchars($result["info"]) . ")" : "") . "</span><br />";
     } else {
         echo "<span class=\"success\">Successfully connected to the POP3 server.</span><br />";
         $temppop3->Disconnect();
         $pop3valid = true;
     }
 } else {
     if ($pop3server == "") {
         echo "<span class=\"error\">POP3:  'POP3 Server' field not filled in.</span><br />";
     } else {
         if ($_REQUEST["user"] == "") {
             echo "<span class=\"error\">POP3:  'Username' field not filled in.</span><br />";
         } else {
             if ($_REQUEST["pass"] == "") {
All Usage Examples Of POP3::Connect