我可以使用 成功发送电子邮件App Engine Mail API
,但我找不到为什么附件没有附加到电子邮件中的问题。我的代码如下所示:
// Pull in the raw file data of the image file to attach it to the message.
$image_data = fopen('gs://pro-sitemaps-api/file.csv');
try {
$message = new Message();
$message->setSender('myemail@****.com');
$message->addTo('myemail@****.com');
$message->setSubject('Subject Google App Engine Test');
$message->setTextBody('Test body');
$message->addAttachment('file.csv', $image_data);
$message->send();
echo 'Mail Sent';
} catch (InvalidArgumentException $e) {
echo 'There was an error'.$e;
}
我的文件托管在Google Storage
(bucket)中。存储文件的文件类型为.csv
谁能告诉我我做错了什么?
编辑:
添加 "mode":"r" 给我这个错误:
$image_data = fopen('gs://pro-sitemaps-api/file.csv', 'r');
输出:
error: {
code: "500",
message: "An error occurred parsing (locally or remotely) the arguments to mail.Send().",
status: "UNKNOWN",
details: [ ]
}
}
编辑:
这可行,但这只会发送顶行(标题)。不是所有的线路。尝试将其添加到数组中并将数组作为附件发送,但随后出现相同的错误。:
$fpmail = fopen('gs://pro-sitemaps-api/file.csv', 'r');
//$attach = fread($fpmail);
$attach = fgets($fpmail);
print_r($attach);
try {
$message = new Message();
$message->setSender('asim@redperformance.no');
$message->addTo('asim@redperformance.no');
$message->setSubject('Test');
$message->setTextBody('Test nyeste');
$message->addAttachment('file.csv', $attach);
$message->send();
echo 'Mail Sent';
} catch (InvalidArgumentException $e) {
echo $e;
}
fclose($fpmail);