Looks like you are sending JSON encoded data while you should respect message/rfc822
format.
You should probably not base64-encode + json-encode your message:
<?php$message = "To: test@example.com\r\nFrom: test@example.com\r\nSubject: GMail test.\r\n My message";$ch = curl_init('https://www.googleapis.com/upload/gmail/v1/users/me/messages/send'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: Bearer $AccessToken", 'Accept: application/json', 'Content-Type: message/rfc822')); curl_setopt($ch, CURLOPT_POSTFIELDS, $message);$data = curl_exec($ch);