传递给 Google_Service_Gmail_UsersMessages_Resource::send() 的参数 2 必须是 Google_Service_Gmail_Message 的实例,给定的字符串

Argument 2 passed to Google_Service_Gmail_UsersMessages_Resource::send() must be an instance of Google_Service_Gmail_Message, string given

我正在使用 Laravel.

开发 Gmail API

我遇到错误:

Argument 2 passed to Google_Service_Gmail_UsersMessages_Resource::send() must be an instance of Google_Service_Gmail_Message, string given

Google_Service_Gmail_Message 的实例是什么?我要给 string 我应该给什么?

我的密码是

public function sendMessage($message) {
try {
$client = $this->getClient();
$service = new Google_Service_Gmail($client);
$userId = 'me';
$message = "test";
$message = $service->users_messages->send($userId, $message);
print 'Message with ID: ' . $message->getId() . ' sent.';
return $message;
} catch (Exception $e) {
 print 'An error occurred: ' . $e->getMessage();
}
}

带有两个参数的 send 方法位于 line 7

//用PHPMailer准备邮件
$mail = new PHPMailer();
$mail->CharSet = "UTF-8";
$邮件->编码= "base64";

//提供你的header信息,body等...
$邮件->主题 = "You've got mail!";
...

//创建 MIME 消息
$mail->preSend();
$mime = $mail->getSentMIMEMessage();
$mime = rtrim(strtr(base64_encode($mime), '+/', '-_'), '=');

//创建 Gmail 邮件

$message = new Google_Service_Gmail_Message();

$message->setRaw($mime);
$message = $service->users_messages->send('me',$message);