SMTP::Authenticate PHP Method

Authenticate() public method

Performs SMTP authentication. Must be run after running the Hello() method. Returns true if successfully authenticated.
public Authenticate ( $username, $password ) : boolean
return boolean
    public function Authenticate($username, $password)
    {
        // Start authentication
        fwrite($this->smtp_conn, 'AUTH LOGIN' . $this->CRLF);
        $rply = $this->get_lines();
        $code = substr($rply, 0, 3);
        if ($code != 334) {
            $this->error = array('error' => 'AUTH not accepted from server', 'smtp_code' => $code, 'smtp_msg' => substr($rply, 4));
            if ($this->do_debug >= 1) {
                echo 'SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />';
            }
            return false;
        }
        // Send encoded username
        fwrite($this->smtp_conn, base64_encode($username) . $this->CRLF);
        $rply = $this->get_lines();
        $code = substr($rply, 0, 3);
        if ($code != 334) {
            $this->error = array('error' => 'Username not accepted from server', 'smtp_code' => $code, 'smtp_msg' => substr($rply, 4));
            if ($this->do_debug >= 1) {
                echo 'SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />';
            }
            return false;
        }
        // Send encoded password
        fwrite($this->smtp_conn, base64_encode($password) . $this->CRLF);
        $rply = $this->get_lines();
        $code = substr($rply, 0, 3);
        if ($code != 235) {
            $this->error = array('error' => 'Password not accepted from server', 'smtp_code' => $code, 'smtp_msg' => substr($rply, 4));
            if ($this->do_debug >= 1) {
                echo 'SMTP -> ERROR: ' . $this->error['error'] . ': ' . $rply . $this->CRLF . '<br />';
            }
            return false;
        }
        return true;
    }

Usage Example

Esempio n. 1
0
 public function Authenticate($username, $password, $authtype = 'LOGIN', $realm = '', $workstation = '')
 {
     $result = false;
     // check if the resource is valid
     if (!is_resource($this->smtp_conn)) {
         $this->error = array("error" => "Not a valid SMTP resource supplied");
     } else {
         $result = parent::Authenticate($username, $password, $authtype, $realm, $workstation);
     }
     $this->handleError();
     return $result;
 }
All Usage Examples Of SMTP::Authenticate