Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

src attribute of <img> is missing when sending mail

Tags:

html

php

email

I am trying to send a HTML mail from php that contains an image.

I receive the email and all the HTML tags look good except for the <img> tag.

The message of the email looks like this:

$message = '<img src="http://your-click.ch/wp-content/uploads/2014/11/logo1.png" alt="Your Click" width="131" height="52" border="0" />';

When I receive the mail, I see that there is an image but it is just blank. When I check the element, I see this code:

<img alt="Your Click" width="131" height="52" border="0">

As you see the whole src attribute is missing? Why?

like image 705
Reza Saadati Avatar asked Aug 31 '25 02:08

Reza Saadati


2 Answers

Some email clients filter out externally linked images for security reasons. Try encoding the image and including it in the body of your message instead of externally linking it.

like image 93
Lance Avatar answered Sep 02 '25 14:09

Lance


The image is probably being filtered by the recipient mail server, try base64_encode the image, i.e.:

$image = file_get_contents('http://your-click.ch/wp-content/uploads/2014/11/logo1.png');
$message = '<img src="data:image/png;base64,'.base64_encode($image).'" alt="Your Click" width="131" height="52" border="0" />';
like image 41
Pedro Lobito Avatar answered Sep 02 '25 14:09

Pedro Lobito