Skip to content

Instantly share code, notes, and snippets.

@phamngsinh
Created July 11, 2016 05:07
Show Gist options
  • Select an option

  • Save phamngsinh/95f8b63a988caf46a06975f77fa003d7 to your computer and use it in GitHub Desktop.

Select an option

Save phamngsinh/95f8b63a988caf46a06975f77fa003d7 to your computer and use it in GitHub Desktop.
gmail api send
$url= "https://www.googleapis.com/upload/gmail/v1/users/me/messages/send";
$header = array('Content-Type: message/rfc822', "Authorization: Bearer $access_token");
$from = "<$user_name> $user_email";
$line = "rn";
$raw = "Content-type: text/html; charset=UTF-8".$line;
$raw .= "To: $to ".$line;
$raw .= "from: $from".$line;
$raw .= "Reply-To: $user_email".$line;
$raw .= "subject: $subject".$line.$line;
//$raw .= "Reply-To: $user_email".$line;
$raw .= $message;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
if( $header !== 0 ){
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
}
curl_setopt($curl, CURLOPT_POST, 1);
if( $data !== 0 ){
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
$response = curl_exec($curl);
$json = json_decode($response, true);
curl_close($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment