Gmail PHP API发送电子邮件 [英] Gmail PHP API Sending Email

查看:135
本文介绍了Gmail PHP API发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to send an email through the Gmail PHP API (https://developers.google.com/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 https://www.googleapis.com/gmail/v1/users/myemailaddress@gmail.com/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发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆