将Gmail API与PHP和curl结合使用,我知道了:
$message = "To: hisemail@domain.com\r\nFrom: myemail@domain.com\r\nSubject: thesubject\r\n The 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 ".$access_token,
'Accept: application/json',
'Content-Type: message/rfc822'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
$data = curl_exec($ch);
curl_close($ch);
效果很好,电子邮件随主题一起发送。但仅主题,而不是内容(“消息”)。 有人知道内容消失了吗?我怎么不更改所有脚本? 非常感谢