-1

I'm falling back from SwiftMailer to PHPMailer.

In SwiftMailer, whenever you want to incorporate images into your HTML emails, you must insert the following line of code for each image within an instantiated Swift_Message object:

$email_msg->embed( Swift_Image::fromPath( $image_path ) );

Do I need to do something similar in PHPMailer? If so, how do I do it?

I cannot find anything in the documentation addressing this issue.

Thanks!

Synchro
  • 35,538
  • 15
  • 81
  • 104
unpocoloco
  • 15
  • 1
  • 5

1 Answers1

0

The equivalent in PHPMailer is addEmbeddedImage. There are many more options available here, but the important usage is:

$mail->addEmbeddedImage($image_path, 'my_image');

This loads the image from the path, and associates it with a content identifier (cid), and then your message body can refer to it with:

<img src="cid:my_image">

This approach relies on your image path containing a file extension (e.g. .png) that can be mapped to a MIME type. If you don't have one, you can set the MIME type yourself, along with the encoding method, which will nearly always be base64.

Synchro
  • 35,538
  • 15
  • 81
  • 104