Can you add inline base64 encoded image to a Mandrill template?

Fjalestad picture Fjalestad · Nov 3, 2014 · Viewed 7.2k times · Source

Does anyone know if and how-to add a Base64 encoded image to a Mandrill Template.

I use a Mandrill template to make sure all my emails have the same look and feel and I have a simple and small logo which I'd prefer to add to my template following these recommendations: http://help.mandrill.com/entries/25252978-Tips-for-using-images-in-Mandrill-emails

However i'm unsure on where and how to add the neccesary code in my HTML template. Anyone have an idea if it's possible and how-to do it?

Thx

Answer

Fjalestad picture Fjalestad · Nov 4, 2014

I have probably found the answer to my own questions.

NO - Mandrill doesn't allow you to add an inline image or to upload the image attachment as code to the template.

SOLUTION - you need to add the array [images] to the $message as suggested in the API.

Here is an PHP example function to do it:

// Add cid image to $message
function add_email_logo($message) {
  $logo = array (
    'images' => array (
      array (
              'type' => 'image/png',
              'name' => 'logo',
              'content' => 'iVBORw0KGgoAAAANSUhEUgAA....etc.'
      )
    )
  );

  return array_merge( $message, $logo);
}

and use the image src="cid:{name}"

<img src="cid:logo"/>