Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stefandoorn/f1e40d8867d48641a75b to your computer and use it in GitHub Desktop.
Save stefandoorn/f1e40d8867d48641a75b to your computer and use it in GitHub Desktop.
Mandrill PHP API filter embedded images array with embedded images used in e-mail HTML content
/**
* Insert list of embedded images (Mandrill API format) & HTML content
* Finds cid elements in HTML and filters $images list with it
* Unused images are shown as attachment in Outlook eg
*
* Format of $images:
*
* $images = array(
* array(
* 'type' => 'image/png',
* 'name' => 'name',
* 'content' => base64_encode(file_get_contents('/path/to/file'))
* ),
* ..
* );
*
* @param array $images
* @param $html
* @return array
*/
static public function stripImagesMandrillAPI(array $images, $html)
{
if(!preg_match_all('/src="cid:(.*)"/Uims', $html, $matches)) {
return $images;
}
return array_filter($images, function($image) use ($matches) {
return in_array($image['name'], $matches[1]);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment