Jump to content

[SOLVED] Include image in Mail


IsmAvatar

Recommended Posts

I'm sending an html message to an email address with the following code:

 

  $email = 'email.html';
  $subject = 'Hello world';
  $mess = file_get_contents($email);
  $headers  = "MIME-Version: 1.0\n";
  $headers .= "Content-type: text/html; charset=iso-8859-1\n";
  $headers .= "To: $to\n";
  $headers .= "From: $from\n";
  
  mail($to,$subject,$mess,$headers);

 

test.html contains some html code and includes an img src with a full url to the image.

I was wondering if there's any other headers I need to add for this to work right, especially in the Mozilla Thunderbird email client. I attempted to send it to myself, and I got the email in its html glory, but the image was blocked, so I told Tbird to unblock it, and the image was still broken (white box square instead of image). The URL works fine because if I load the given html page in my browser, the image shows up.

Link to comment
https://forums.phpfreaks.com/topic/102556-solved-include-image-in-mail/
Share on other sites

I don't know how thunderbird works, but make sure you include full url, all with http://www.domainname.com/ stuff.

 

Different mail programs will strip/parse html differently. Some allows more than others. Gmail for example, will strip most 'style' attributes, so you can't use css images.

the url is full. For example:

 

<img src="http://www.phpfreaks.com/images/logo_main.jpg">

 

does not display in the email. Instead, it appears as a broken image.

 

The HTML code is very simple, with no CSS or anything fancy in there, just <br> tags and an <img src>, along with the <html> and <body> tags

I'm afraid I don't know much about Thunderbird.

 

Perhaps you can try emailing your non-thunderbird mailboxes, and see how they interpret the html. If it's a Thunderbird-only problem, you may want to ask a question @ mozillazine.org forum.

 

The code itself looks correct to me.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.