Send Email with PHPmailer - Embed Image in Body

Send email with PHPMailer - embed image in body

I found the answer:

$mail->AddEmbeddedImage('img/2u_cs_mini.jpg', 'logo_2u');

and on the <img> tag put src='cid:logo_2u'

How to embed image in phpmailer - I can't do it, why?

Add on the <img> tag put src='cid:Kartka'

$mail->AddEmbeddedImage('images/Kartka.png', 'Kartka');
$mail->Body = "<h1>Test 1 of PHPMailer html</h1><p>This is a test</p>";
"<p>This is a test picture: <img src=\"cid:Kartka\" /></p>";

Why you use so much \ ?? you can do it also like this :

<img src="cid:Kartka"/>

Adding embedded images within mail body phpmailer class

Don't use $mailer->AddEmbeddedImage, but directly add

<img src="http://.../images/namDiams.png" /> instead.

The mail length should be lighter... And it works.

EDIT

I don't know if it will help you but there is a little mistake here :

$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png');

Should be

$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDiames.png');//the last param the second 'a' was missing...

Another topic here

Embed Image in Mail without having physical Image File

It always helps to read the docs. The function you're looking for is addStringEmbeddedImage, which does exactly what you want:

$URL = "http://maps.googleapis.com/maps/api/staticmap?center=Albany,+NY&zoom=13&scale=false&size=600x300&maptype=roadmap&format=png&visual_refresh=true";
$image = file_get_contents($URL);
$mail->addStringEmbeddedImage($image, 'staticMap', 'map.png', 'base64', 'image/png');
$mail->Body = '<img width="600" height="300" src="cid:staticMap">';

There are indeed pros and cons to using embedded images, but data urls have especially poor client compatibility, so are generally the worst option. Dynamically linking to the image may not be reliable with google maps, so you may want to proxy and cache the direct map lookups. This will also be much faster than hitting the API every time, and also more reliable as you can deliver an older version if the API doesn't respond or is slow.

How can I embed an image into an email acceptable to Outlook

Most email clients do not support Base 64 images in the HTML. (See https://www.caniemail.com/features/image-base64/)

However, you can add your image as a CID embedded attachment to your email, and then link to that in your HTML email.

Here’s another Stack Overflow thread answering this question : How to embed images in html email

What is the most common way to send email that contains an image from a database via phpMailer?

The solution that worked for me using an image that was encoded as base64.

$image_data = explode(',', $_SESSION['icon_data']);
$image_data = base64_decode($image_data[1]);
$icon = $image_data;

Before, I just tried to decode the whole column cell; I didn't realize there was a comma in the data that I needed to split using explode, and only use the second index which was the actual base64 data.

from here, I just used the addStringEmbeddedImage:

$w_mail->addStringEmbeddedImage($icon, 'img', '', 'base64', "image/png");

Works for now. Thank you all for the feedback and the help



Related Topics



Leave a reply



Submit