【问题标题】:Google Apps Engine PHP Mail API - $image_dataGoogle Apps Engine PHP 邮件 API - $image_data
【发布时间】:2015-03-12 21:48:51
【问题描述】:

在官方 GAE PHP Mail 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。 有什么帮助吗?如果它可以是明确的,那就太好了

谢谢 迭戈

【问题讨论】:

    标签: php api google-app-engine


    【解决方案1】:

    使用 file_get_contents() 检索您要作为电子邮件的一部分发送的数据。

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

    或者您可以发送存储在 Cloud Storage 中的图像

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多