Helper\Mailer\Smtp::sendCommandSecurity PHP Method

sendCommandSecurity() protected method

安全连接发送命令
protected sendCommandSecurity ( string $command, integer $code ) : boolean
$command string 发送到服务器的smtp命令
$code integer 期望服务器返回的响应吗
return boolean
    protected function sendCommandSecurity($command, $code)
    {
        try {
            if (fwrite($this->_socket, $command)) {
                //当邮件内容分多次发送时,没有$code,服务器没有返回
                if (empty($code)) {
                    return true;
                }
                //读取服务器返回
                $data = trim(fread($this->_socket, 1024));
                if ($data) {
                    $pattern = "/^" . $code . "+?/";
                    if (preg_match($pattern, $data)) {
                        return true;
                    } else {
                        $this->_errorMessage = "Error:" . $data . "|**| command:";
                        return false;
                    }
                } else {
                    return false;
                }
            } else {
                $this->_errorMessage = "Error: " . $command . " send failed";
                return false;
            }
        } catch (Exception $e) {
            $this->_errorMessage = "Error:" . $e->getMessage();
        }
    }