【问题标题】:Inline multiple images Mailgun API Batch内联多个图像 Mailgun API Batch
【发布时间】:2016-12-10 00:10:12
【问题描述】:

我正在尝试通过 Mailgun 的内联 API 参数传递多个图像。我只使用一张图片没有问题,但是当我尝试使用多张图片时 - 如下面的代码所示 - 只有数组中的最后一张图片会显示在电子邮件中。

$template = View::make('emails.template')->render();
$result = $mgClient->sendMessage($domain, array(
  'from'                =>  $sender,
  'to'                  =>  implode(',',$emailAddresses),
  'subject'             =>  '%recipient.subject%',
  'text'                =>  $messageText,
  'recipient-variables' =>  json_encode($credentials),
  'html'                =>  $template
), array(
  'inline'              =>  array(
    'path/to/image1.png',
    'path/to/image2.png',
    'path/to/image3.png',
    'path/to/image4.png')
));

上面的代码就像数组中的最后一个元素是唯一的元素一样工作。

使用 Mailgun 发送内联图像的文档位于 here,据说 here “您可以发布多个内联值”,这意味着我肯定做错了。

【问题讨论】:

  • 你用的是官方的mailgun SDK,对吧?
  • @user866762,是的,我是

标签: php laravel inline mailgun


【解决方案1】:

试试这个:

$result = $mgClient->sendMessage($domain, array(
  'from'                =>  $sender,
  'to'                  =>  implode(',',$emailAddresses),
  'subject'             =>  '%recipient.subject%',
  'text'                =>  $messageText,
  'recipient-variables' =>  json_encode($credentials),
  'html'                =>  $template
), array(
  'inline'              =>  array(
    array('path/to/image1.png'),
    array('path/to/image2.png'),
    array('path/to/image3.png'),
    array('path/to/image4.png')
)));

基本上将每个图像路径包装在一个数组中。

还有$template的内容是什么?

【讨论】:

  • 当我这样做时,我收到以下错误消息:“RestClient.php 第 259 行中的 ErrorException:未定义索引:remoteName”。我还更新了我的问题,以便您可以查看 $template 中的内容。基本上它只是我的 html 代码作为字符串。
  • 嗯,是的,如果没有文档中的多个图像示例,这是一个艰难的过程。您可能需要联系他们。查看this post。说他们为 Mailgun 工作的人留下了一个答案(尽管它适用于 Python,但我确信同样的原则适用) - 也许他可以提供帮助?
  • 我就我的问题联系了他,如果我收到来自 stackoverflow 外部的任何回复,我会及时更新这篇文章。感谢您的帮助!
  • 酷,我也很想知道解决方案是什么。
【解决方案2】:

这实际上是最近引入的错误。新的拉取请求已提交给官方 Mailgun PHP SDK,更多信息请参见here

所以回答这个问题:只要根据上述拉取请求更新 SDK,代码就可以正常工作。现在我相应地编辑了我的本地 mailgun-php 副本,它运行良好。非常感谢 Mailgun 上的 Travis Swientek 的快速响应。

【讨论】:

  • 太棒了!进展顺利。
猜你喜欢
  • 2014-11-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-02
  • 2018-08-01
  • 2016-10-11
  • 2013-02-24
相关资源
最近更新 更多