I’ll keep this one short and fast:
PHPMailer has lots of features, even if it’s a bit old.
One great feature is that it allows you to embed images inline within your e-mail’s body. In most email clients, the inline embedded images are shown in their right place just as on a web page and are “also” in the attachements list.
To be able to use this feature, proceed as follows:
1- Instantiate PHPMailer:
$mail = new PHPMailer(true); $mail->CharSet='UTF-8'; ... ... //Path to image file (use full path) $filepath= '/path/to/file/logo_mail.jpg'; //File token ID, use unique interger. $filecid = 1001; //File name which will be in the mail, overrides default filename. $filename= 'shop-logo.jpg'; //Encoding $encodingtouse = 'base64'; //File type MIME $filemime = 'image/jpeg'; //EMBED IT $mail->AddEmbeddedImage($filepath, $filecid, $filename, $encoding, $filemime); //Message Html Body $mail->MsgHTML(file_get_contents('/path/to/contents.html'));
2- In your /path/to/contents.html file, which is your mail template message, you can include the inline image. Use this syntax for the <img> tag:
<img src=”cid:1001” alt=”shop logo used in emails” width=”182″ height=”75″ />
Note the CID here, it should be the same as the one you defined for your embedded inline image.
Tested and working with PHPMailer 5.1 on GMAIL, Yahoo!Mail and Mac Mail application