Embed Images in PHPMailer

By | 20/05/2011

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:

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


ref: http://www.sitepoint.com/forums/php-34/embed-images-phpmailer-586789.html

Category: Ramblings Tags: , ,

About Gi

I love new technologies and try to use them in my everyday life. Since many years ago, I write about these technologies, and provide solutions to the issues people might get using the new world. I tested and experienced the solutions I provide. I love helping people, and that's why my publications have been free until now.

2 thoughts on “Embed Images in PHPMailer

  1. Rajesh

    Hello, I tried this procedure to send image via Phpmailer.

    But i got an error in email, I am using version 2.14.6

    Is this compatible or any other procedure….

  2. Denis

    Thanks for posting this, it really helped.

    For some reason, the $filemime or $encoding, were killing the success for me. I removed those from the line and then it worked.

    Thanks again


Leave a Reply

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

CommentLuv badge