Gmail PHP API发送电子邮件

编程入门 行业动态 更新时间:2024-10-27 12:30:27
本文介绍了Gmail PHP API发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试通过Gmail PHP API发送电子邮件( developers.google/gmail/api/v1/reference/users/messages/send ).一切似乎都可以完成,直到我发送邮件为止.我的代码是:

I am trying to send an email through the Gmail PHP API (developers.google/gmail/api/v1/reference/users/messages/send). Everything seems to work up to the point that I send the message. My code is:

private function createMessage($email) { $message = new Google_Service_Gmail_Message(); $message->setRaw(strtr(base64_encode($email), '+/=', '-_,')); // $email is a raw email data string return $message; } public function sendMessage($userID, $email) { try { $msg = $this->createMessage($email); $this->service->users_messages->send($userID, $msg); } catch (Exception $e) { print 'An error occurred: ' . $e->getMessage(); } }

代码在以下行中断:

$this->service->users_messages->send($userID, $msg);

出现错误:

An error occurred: Error calling POST www.googleapis/gmail/v1/users/myemailaddress@gmail/messages/send: (400) Invalid value for ByteString:

你知道这里发生了什么吗?谢谢!

Any idea what is happening here? Thanks!

推荐答案

您设置为原始"的电子邮件字符串必须使用 URL安全 base64编码(字母略有不同).

The email string you set to 'raw' needs to be url safe base64 encoded (slightly different alphabet).

更多推荐

Gmail PHP API发送电子邮件

本文发布于:2023-10-07 10:25:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469135.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送电子邮件   Gmail   PHP   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!