Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, phpMailer can transform images from external to inline. This can be done using the addEmbeddedImage method. This method takes the image file path as an argument and returns an identifier that can be used in the body of the email message.

Here's an example of how to use addEmbeddedImage:

$mail = new PHPMailer(true);

// Attach an external image as inline content
$imagePath = '/path/to/image.jpg';
$imageContent = file_get_contents($imagePath);
$imageCID = $mail->addEmbeddedImage($imagePath, 'img-1');

// Add the image to the HTML body of the message
$htmlBody = '<html><body><img src="cid:' . $imageCID . '"></body></html>';
$mail->msgHTML($htmlBody);

// Send the message
$mail->send();

In this example, the addEmbeddedImage method is used to attach an external image as inline content. The method returns an identifier (img-1) that can be used in the HTML body of the message to reference the image. The image is then added to the HTML body using the msgHTML method, which is used to set the HTML content of the message. Finally, the message is sent using the send method.