我能够通过gmail api发送电子邮件,没有任何错误,但即使我有来自姓名的标题(即来自:< Dummy name> dummy@gmail.com),当电子邮件发送时,它只显示电子邮件地址和不是名字。
我正在使用的代码:
$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 = "\r\n";
$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);