Skip to content

Commit

Permalink
Support images with data: uri's in HTML message
Browse files Browse the repository at this point in the history
  • Loading branch information
EionRobb committed Aug 10, 2014
1 parent a666aea commit 9344404
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions class.phpmailer.php
Expand Up @@ -2878,6 +2878,23 @@ public function msgHTML($message, $basedir = '', $advanced = false)
preg_match_all('/(src|background)=["\'](.*)["\']/Ui', $message, $images);
if (isset($images[2])) {
foreach ($images[2] as $imgindex => $url) {
// convert data: uri's into embedded images
if (preg_match('#^data:(image[^;,]*)(;base64)?,#', $url, $match)) {
$data = substr($url, strpos($url, ','));
if ($match[2]) {
$data = base64_decode($data);
} else {
$data = rawurldecode($data);
}
$cid = md5($url) . '@phpmailer.0'; // RFC2392 S 2
if ( $this->addStringEmbeddedImage($data, $cid, '', 'base64', $match[1]) ) {
$message = preg_replace(
'/' . $images[1][$imgindex] . '=["\']' . preg_quote($url, '/') . '["\']/Ui',
$images[1][$imgindex] . '="cid:' . $cid . '"',
$message
);
}
} else
// do not change urls for absolute images (thanks to corvuscorax)
if (!preg_match('#^[A-z]+://#', $url)) {
$filename = basename($url);
Expand Down

0 comments on commit 9344404

Please sign in to comment.