Skip to content Skip to sidebar Skip to footer

Can You Add Inline Base64 Encoded Image To A Mandrill Template?

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 simp

Solution 1:

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}"

<imgsrc="cid:logo"/>

Solution 2:

In Mandril example

<imgsrc="cid:image_name">

Should be replaced with

<imgsrc="cid:image_name" />

Else, image will be just attached to mail, not shown inside

Solution 3:

It's also very important to note that the images[].content & attachments[].content property must be a base64 string without any data:(MIME TYPE);base64, construction in the beginning, just a string

Post a Comment for "Can You Add Inline Base64 Encoded Image To A Mandrill Template?"