Google API Gmail-奇怪的电子邮件
我正在使用此功能发送电子邮件。
function sendMessage($to, $subject, $messageBody, $Cc)
{
$service = getGoogleGmailService();
$message = new \Google_Service_Gmail_Message();
$rawMessageString = "From: 'My name' <me>\r\n";
$rawMessageString .= "To: <" . $to . ">\r\n";
if (!empty($Cc)) {
$rawMessageString .= "Cc: <" . $Cc . ">\r\n";
}
$rawMessageString .= 'Subject: =?utf-8?B?' . base64_encode($subject) . "?=\r\n";
$rawMessageString .= "MIME-Version: 1.0\r\n";
$rawMessageString .= "Content-Type: text/html; charset=utf-8\r\n";
$rawMessageString .= 'Content-Transfer-Encoding: base64' . "\r\n\r\n";
$rawMessageString .= $messageBody . "\r\n";
$rawMessage = strtr(base64_encode($rawMessageString), array('+' => '-', '/' => '_'));
$message->setRaw($rawMessage);
try {
$message = $service->users_messages->send('me', $message);
return $message->getId();
} catch (Exception $e) {
return $e->getMessage();
}
}
在第一张照片中,应该如何构造电子邮件,实际上一切都可以。但是,每隔一段时间,我都会收到一封奇怪的电子邮件,就像第二张照片一样,就好像它仍然是编码或其他东西一样。 可能是什么?
I am using this function for send emails.
function sendMessage($to, $subject, $messageBody, $Cc)
{
$service = getGoogleGmailService();
$message = new \Google_Service_Gmail_Message();
$rawMessageString = "From: 'My name' <me>\r\n";
$rawMessageString .= "To: <" . $to . ">\r\n";
if (!empty($Cc)) {
$rawMessageString .= "Cc: <" . $Cc . ">\r\n";
}
$rawMessageString .= 'Subject: =?utf-8?B?' . base64_encode($subject) . "?=\r\n";
$rawMessageString .= "MIME-Version: 1.0\r\n";
$rawMessageString .= "Content-Type: text/html; charset=utf-8\r\n";
$rawMessageString .= 'Content-Transfer-Encoding: base64' . "\r\n\r\n";
$rawMessageString .= $messageBody . "\r\n";
$rawMessage = strtr(base64_encode($rawMessageString), array('+' => '-', '/' => '_'));
$message->setRaw($rawMessage);
try {
$message = $service->users_messages->send('me', $message);
return $message->getId();
} catch (Exception $e) {
return $e->getMessage();
}
}
In the first photo it is how the email should be structured, in fact everything arrives ok. Every so often, however, I receive a strange email, as in the second photo, as if it were still encoded or something else.
What could it be ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论