Quantcast
Channel: How to send an email, using google gmail api in php with cURL? - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Patrick Allaert for How to send an email, using google gmail api in php with cURL?

$
0
0

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);

Viewing all articles
Browse latest Browse all 2

Trending Articles