内联多个图像Mailgun API Batch

时间:2016-08-04 02:42:44

标签: php laravel inline mailgun

我试图通过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表示{&3;}"您可以发布多个内联值"这意味着我肯定做错了什么。

2 个答案:

答案 0 :(得分:2)

尝试一次:

$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的内容是什么?

答案 1 :(得分:2)

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

所以回答这个问题:一旦根据上面的pull请求更新SDK,代码就可以了。现在我相应地编辑了我的本地邮件mailgun-php,它运行正常。非常感谢Mailgun的Travis Swientek快速回复。