Ask Your Question
4

Can phpMailer transform images from external to inline?

asked 2023-06-18 10:49:05 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-06-18 10:59:02 +0000

scrum gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-18 10:49:05 +0000

Seen: 13 times

Last updated: Jun 18 '23