PHPMailer : inline image seen as attachment

There is an issue with PHPMailer and AddEmbeddedImage method.

In some email client, you will get image as an attachment and not inline as expected.

To fix that, patch the class.phpmailer.php with following :

$disposition = $this->attachment[$i][6];
$cid         = $this->attachment[$i][7];

// patch
$path_parts = pathinfo($filename);
$extension = $path_parts[‘extension’];
// end patch

$mime[] = sprintf(“–%s%s”, $this->boundary[1], $this->LE);

// patch
//$mime[] = sprintf(“Content-Type: %s; name=\”%s\”%s”, $type, $name, $this->LE);
$mime[] = sprintf(“Content-Type: image/”.$extension.”;\n”);
// end patch
$mime[] = sprintf(“Content-Transfer-Encoding: %s%s”, $encoding, $this->LE);

if($disposition == “inline”)
$mime[] = sprintf(“Content-ID: <%s>%s”, $cid, $this->LE);

Leave a Reply

Your email address will not be published. Required fields are marked *