I am trying to send an email through the Gmail PHP API (https://developers.google.com/gmail/api/v1/reference/users/messages/send). Everything seems to work up to the point that I send the message. My code is:
private function createMessage($email) {
$message = new Google_Service_Gmail_Message();
$message->setRaw(strtr(base64_encode($email), '+/=', '-_,')); // $email is a raw email data string
return $message;
}
public function sendMessage($userID, $email) {
try {
$msg = $this->createMessage($email);
$this->service->users_messages->send($userID, $msg);
} catch (Exception $e) {
print 'An error occurred: ' . $e->getMessage();
}
}
The code is breaking at the line:
$this->service->users_messages->send($userID, $msg);
with the error:
An error occurred: Error calling POST https://www.googleapis.com/gmail/v1/users/[email protected]/messages/send: (400) Invalid value for ByteString:
Any idea what is happening here? Thanks!