在官方的 GAE PHP 邮件 API 文档中 https://cloud.google.com/appengine/docs/php/mail/他们展示了这个例子:
use 'google'appengine'api'mail'Message;
// Notice that $image_data is the raw file data of the attachment.
try
{
$message = new Message();
$message->setSender("from@google.com");
$message->addTo("to@google.com");
$message->setSubject("Example email");
$message->setTextBody("Hello, world!");
$message->addAttachment('image.jpg', $image_data, $image_content_id);
$message->send();
} catch (InvalidArgumentException $e) {
// ...
}
但他们没有解释如何用上传的静态文件填充 $image_data。有什么帮助吗?如果可以明确,那就太好了
谢谢迭 戈
使用 file_get_contents() 检索要作为电子邮件的一部分发送的数据。
$image_data = file_get_contents('path/to/static/file.jpg');
或者您可以发送存储在云存储中的图像
$image_data = file_get_contents('gs://my_bucket/path/to/file.jpg');