Skip to content

Instantly share code, notes, and snippets.

@wanmigs
Created April 4, 2019 01:14
Show Gist options
  • Save wanmigs/c9f01726405fb6c4e17f7e54bbcadf01 to your computer and use it in GitHub Desktop.
Save wanmigs/c9f01726405fb6c4e17f7e54bbcadf01 to your computer and use it in GitHub Desktop.
Swiftmailer embed data image
protected function getImagesFromMsg($msg)
{
if (!empty($msg))
{
preg_match_all('/<img[^>]+>/i', stripcslashes($msg), $imgTags);
//All img tags
for ($i=0; $i < count($imgTags[0]); $i++)
{
preg_match('/src="([^"]+)/i', $imgTags[0][$i], $withSrc);
//Remove src
$withoutSrc = str_ireplace('src="', '', $withSrc[0]);
//data:image/png;base64,
if (strpos($withoutSrc, ";base64,"))
{
$cid = $this->message->embed(\Swift_Image::fromPath($withoutSrc));
$msg = str_replace($withoutSrc, $cid, $msg);
}
}
}
return $msg;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment