Skip to content

Possible bug within MsgHTML for embedding images #60

Closed
@mikehdt

Description

I believe there's a bug in PHPMailer for embedding images. The issue - as far as I can tell - is that that cid: use with AddEmbeddedImage is incorrect.

Around line 2491, this line exists:
$cid = 'cid:'. md5($url).'@phpmailer.0'; //RFC2392 S 2

This creates a string with the prefix of cid: at the front, which is later passed to AddEmbeddedImage and this appears to be the issue, as the cid: prefix should not be passed as part of the CID. Instead of embedding the image, it comes through as a standard attachment.

Here's how I fixed it. I removed the cid: prefix from here:
$cid = md5($url).'@phpmailer.0'; //RFC2392 S 2

And added it back in the preg_replace on line 2496 here:
$message = preg_replace("/".$images[1][$i]."=["']".preg_quote($url, '/')."["']/Ui", $images[1][$i]."="cid:".$cid.""", $message);

Test it out, make sure I'm making sense. Thanks!

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions