How to embed images using PHPMailer

H

How Can We Help?

  1. Use the AddEmbeddedImage method provided by the PHPMailer class.
    eg. $mail->AddEmbeddedImage(‘test.gif’,’testImage’,’test.gif’);
  2. Parameters for AddEmbeddedImage($path, $cid, $name = ”, $encoding = ‘base64’, $type = ‘application/octet-stream’)
    1. $path Path to the attachment
    2. $cid = Content ID of the attachment.  Use this to identify the Id for accessing the image in an HTML form.
    3. $name = Overrides the attachment name.
    4. $encoding = File encoding
    5. $type = File extension (MIME) type.

Example:

<?php
          //Include the PHPMailer class
          include = 'class.phpmailer.php';

         $mailer=new phpmailer();
         $mailer->From =’[email protected]’;
         $mailer->FromName=’TechPortal';
         $mailer->Subject =’TechPortal Example’;
         $mailer->AddAddress(’[email protected]’);

         $mailer->IsHTML(true);
         $mailer->AddEmbeddedImage(’test.gif’,'testImage’,'test.gif’);
         $mailer->Body =’<img src=”cid:testImage”>’;

         $mailer->Send();
?> 

DOWNLOAD PHPMailer Class (Version: 2.0.4)

About the author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

About Author

Ian Carnaghan

I am a software developer and online educator who likes to keep up with all the latest in technology. I also manage cloud infrastructure, continuous monitoring, DevOps processes, security, and continuous integration and deployment.

Follow Me