Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inline multiple images Mailgun API Batch

I am trying to pass multiple images via Mailgun's inline API-parameter. I have no problem with only one image, but when I try with multiple images - as in the code below - only the last image in the array is displayed in the email.

$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')
));

The code above works as if the last element in the array is the only element.

The documentation for sending inline images with Mailgun is found here and it's said here that "You can post multiple inline values" which means that I'm definitely doing something wrong.

like image 203
Joel Avatar asked Aug 04 '16 02:08

Joel


2 Answers

Try this once:

$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')
)));

Basically wrapping each image path in an array.

Also what is the contents of $template?

like image 149
Jared Eitnier Avatar answered Nov 18 '22 00:11

Jared Eitnier


This was actually a recently introduced bug. A new pull request has been submitted to the official Mailgun PHP SDK, for more info see here.

So to answer the question: the code is working fine, as soon as the SDK is updated according to above pull request. For now I edited my local copy of mailgun-php accordingly and it worked fine. Many thanks to Travis Swientek on Mailgun for quick response.

like image 2
Joel Avatar answered Nov 18 '22 00:11

Joel