小编Sre*_* PM的帖子

使用Gmail新API发送带附件的邮件,但不会显示给收件人的收件箱

我们正在使用他们提供的最新API集成GMail,作为在我们的应用程序中开发电子邮件客户端的一部分.我们正在使用Google提供的PHP客户端库.

请参阅链接https://developers.google.com/api-client-library/php/

在这里我试图发送带附件的邮件.这里我们生成了message/rfc822兼容文本,并使用'raw'参数传递它.这里我发现的问题是,在执行代码后,当我检查发送的邮件是否通过GMail API发送的邮件时,附件显示正确.但是没有收到/显示发件人的邮箱.

有关详细信息,请参阅代码:

require_once DOCUMENT_ROOT . '/../library/google/src/Google/Client.php';
require_once DOCUMENT_ROOT . '/../library/google/src/Google/Service/Gmail.php';

function encodeRecipients($recipient){
    $recipientsCharset = 'utf-8';
    if (preg_match("/(.*)<(.*)>/", $recipient, $regs)) {
        $recipient = '=?' . $recipientsCharset . '?B?'.base64_encode($regs[1]).'?= <'.$regs[2].'>';
    }
    return $recipient;
}

$isAccessCodeExpired = 0;
$arrAccessToken = array();
$session = new Zend_Session_Namespace();

$client = new Google_Client();
$client->setClientId($this->client_id);
$client->setClientSecret($this->client_secret);
$client->setRedirectUri($this->redirect_uri);
$client->setAccessType('offline');
$client->setApprovalPrompt('force');

$client->addScope("https://mail.google.com/");
$client->addScope("https://www.googleapis.com/auth/gmail.compose");
$client->addScope("https://www.googleapis.com/auth/gmail.modify");
$client->addScope("https://www.googleapis.com/auth/gmail.readonly");


if ($this->getRequest()->getParam('code')) {
    $code = $this->getRequest()->getParam('code');
    $client->authenticate($code);
    $session->gmail_access_token = $client->getAccessToken();
    //$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    $redirect = BASE_PATH . …
Run Code Online (Sandbox Code Playgroud)

php email gmail attachment gmail-api

6
推荐指数
1
解决办法
3238
查看次数

标签 统计

attachment ×1

email ×1

gmail ×1

gmail-api ×1

php ×1