Php 使用Gmail API发送大型附件
根据Gmail API,要发送附件大于5MB的大型电子邮件,您需要使用以下说明: API对细节不是很清楚,我尝试使用我在这里找到的解释: 每次我都会收到“实体太大””错误消息 有人可以通过Gmail API成功地发送一个大于5MB的附件,帮助我理解我做错了什么 我的作曲家文件:Php 使用Gmail API发送大型附件,php,gmail-api,Php,Gmail Api,根据Gmail API,要发送附件大于5MB的大型电子邮件,您需要使用以下说明: API对细节不是很清楚,我尝试使用我在这里找到的解释: 每次我都会收到“实体太大””错误消息 有人可以通过Gmail API成功地发送一个大于5MB的附件,帮助我理解我做错了什么 我的作曲家文件: { "require": { "google/apiclient": "^2.0", "pear/mail_mime": "^1.10" } } 阅读所有内容后,我的
{
"require": {
"google/apiclient": "^2.0",
"pear/mail_mime": "^1.10"
}
}
阅读所有内容后,我的代码如下:
<?php
set_time_limit(100);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once __DIR__ . '/vendor/autoload.php';
require_once 'client.php';
$googleClient = getClient();
$mailService = new Google_Service_Gmail($googleClient);
$message = new Google_Service_Gmail_Message;
$file = __DIR__ . '/pexels-photo.jpg';
$mime = new Mail_mime;
$mime->addTo('mymail@domain.com');
$mime->setTXTBody('');
$mime->setSubject('test');
$mailMessage = base64_encode($mime->getMessage());
$message->setRaw($mailMessage);
$request = $mailService->users_messages->send(
'me',
$message,
array( 'uploadType' => 'resumable' )
);
$googleClient->setDefer(true);
$media = new Google_Http_MediaFileUpload(
$googleClient,
$request,
'message/rfc822',
$mailMessage,
$resumable = true,
$chunkSizeBytes = 1 * 1024 * 1024
);
$media->setFileSize(filesize($file));
$status = false;
$handle = fopen($file, 'rb');
while (! $status && ! feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
$googleClient->setDefer(false);
@MP在我的例子中,问题是我需要设置未编码的消息大小,而不是实际的文件大小。像这样:
$media->setFileSize(strlen($message));
文件上说,使用更大的文件。你试过了吗?你读过我的代码吗?可能是@JakeSymons的复制品,真的吗?“我怎么能重复昨天提出的问题呢?”@YehudaHassine,你能解决这个问题吗?我也面临同样的问题。如果我附加一个3.7MB的有效负载大小为7.5MB的文件,如果我上载两个这样的文件,它将达到14MB,我会得到“实体太大”错误。如果您能够修复,请共享。