Helper\Mailer\Smtp::sendCommand PHP Method

sendCommand() protected method

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