Php 및 cURL에서 Google Api를 사용하여 메일을 보내는 데 문제가 있습니다.
나는 이것을 시도했다 :
// ENVOIE EMAIL
$message="To: [email protected]\r\nFrom: [email protected]\r\nSubject: GMail test.\r\n My message";
$email=base64_encode($message);
$url_email = 'https://www.googleapis.com/upload/gmail/v1/users/me/messages/send';
$curlPost = array(
'raw' => $email,
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_email);
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: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($curlPost));
$data = curl_exec($ch);
// $data = json_decode(curl_exec($ch), true);;
curl_close($ch);
echo '<br/><h2>Send email</h2>';
print_r($data);
하지만 다음과 같은 오류 메시지가 나타납니다.
{ "error": { "errors": [{ "domain": "global", "reason": "badContent", "message": "미디어 유형 'application / json'은 지원되지 않습니다. 유효한 미디어 유형 : [message / rfc822] "}],"code ": 400,"message ":"미디어 유형 'application / json'은 지원되지 않습니다. 유효한 미디어 유형 : [message / rfc822] "}}
그리고 내가 시도했을 때 :
'Content-Type: message/rfc822';
새로운 오류 메시지가 있습니다.
{ "error": { "errors": [{ "domain": "global", "reason": "invalidArgument", "message": "Recipient address required"}], "code": 400, "message": "수신자 주소 필요"}}
Google에서 제공하는 라이브러리를 사용하고 싶지 않습니다.
당신 같은 외모는 존중해야 동안 JSON 데이터를 인코딩 보내는 message/rfc822
형식을 .
메시지를 base64 인코딩 + json 인코딩하면 안됩니다.
<?php
$message = "To: [email protected]\r\nFrom: [email protected]\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);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다