Google Apps Engine PHP Mail API - $image_data

北城余情 提交于 2020-02-07 12:29:50

问题


in the official GAE PHP Mail Api doc https://cloud.google.com/appengine/docs/php/mail/ they show this example:

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) {
  // ...
}

but they dont explain how to fill $image_data with an uploaded static file. any help ? if it can be explicit it will be great

thanks diego


回答1:


Use file_get_contents() to retrieve the data you want to send as part of the email.

$image_data = file_get_contents('path/to/static/file.jpg');

Or you can send an image stored in Cloud Storage

$image_data = file_get_contents('gs://my_bucket/path/to/file.jpg');


来源:https://stackoverflow.com/questions/29020871/google-apps-engine-php-mail-api-image-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!