Created
April 4, 2019 01:14
-
-
Save wanmigs/c9f01726405fb6c4e17f7e54bbcadf01 to your computer and use it in GitHub Desktop.
Swiftmailer embed data image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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