5

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.

Joel
  • 184
  • 1
  • 10

2 Answers2

2

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?

Jared Eitnier
  • 7,012
  • 12
  • 68
  • 123
  • when I do that I get following error message: "ErrorException in RestClient.php line 259: Undefined index: remoteName". I also updated my question so you can see what's in $template. Basically it's just my html-code as a string. – Joel Aug 04 '16 at 07:22
  • 1
    Hmm, yeah this is a tough one without an example of multiple images in the docs. You might need to reach out to them. Check out [this post](http://stackoverflow.com/a/15302750/1133306). Someone who says they work for Mailgun left an answer (although it's for Python I'm sure the same principle applies) - maybe he can help? – Jared Eitnier Aug 04 '16 at 13:19
  • I contacted him about my question, will keep this post updated if I get any response from outside stackoverflow. Thanks for your help! – Joel Aug 04 '16 at 21:14
  • Cool, I'm curious to see what the solution is too. – Jared Eitnier Aug 04 '16 at 21:27
2

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.

Joel
  • 184
  • 1
  • 10