tags:

views:

43

answers:

2

Hi,

I am trying to send an e-mail using the following code:

$htmlHeaders="";
$htmlHeaders  = "MIME-Version: 1.0 \r\n";
$htmlHeaders .= "Content-type: text/html; charset=iso-8859-1 \r\n";
$htmlHeaders .= "X-Mailer: PHP/" . phpversion(). "\r\n";
$htmlHeaders .= "From: System <[email protected]> \r\n";

mail("[email protected]","Subject",'New test <img src="http://www.someserver/image.jpg"&gt;',$htmlHeaders);

what I noticed is that for some images (I always link the images through an http link) are working fine and the mail is delivered correctly, while for some other images I get problems; that is, the image is NOT delivered.

For example, trying to use this image wont work: http://img826.imageshack.us/img826/2601/gitaallago.png

I guess it is a problem of headers, but I really do not understand how to fix this.

Any hints?

+1  A: 

Often times the problem is the mail client. Some mail clients by default will only download images under a certain size, some will not download any images at all.

Your best bet (though it can be quite a lot more work than what you're doing now) is to attach the image to the email with a CID and reference the image that way (<img src="cid:whatever">)

It will increase the size of your email because you have to transmit the image with each email, but it will display in far more mail clients that way.

MightyE
Thanks for your answer! I cannot do that job because it wont be me using this, but my users will basically just cut past an HTML template. Anyway I guess the size is not the matter. I tried with a very big image (5000x4000px) and received it, but with certain other images.. I simply dont get the email... and I am testing this with my gmail account :)
Danilo
The entire email doesn't appear? That suggests that either the non-arriving emails end up as an invalid mail request in some way, or maybe your provider's email system has been configured to block email with certain patterns (as an anti-spam solution). Retry the same email with a tinyurl version of the blocked image.
MightyE
Yes, the entire mail does not appear, actually it does not get sent, as I do not get it neither in the inbox nor in the SPAM folder... Actually I tried with this image http://img651.imageshack.us/img651/493/mapu.png and it works with this tinyurl... http://tinyurl.com/359rpn5
Danilo
A: 

Is the correct MIME type being served by the server for the images?

You didn't make it clear whether or not you're saving the image on your server, and linking to it from there, or linking to it straight from Imageshack (in this example.) If you're linking straight from Imageshack, then MIME types definitely aren't the problem. Worth looking into, however, if you're hosting the images on your server.

chigley
Hey, thanks for your answer. So you mean MIME is not an issue if you just link images? I do not have images on my server, I just link external images all the time (straight as you say)
Danilo
MIME could be the issue, it was just a suggestion.The point I was making is that, with the example image you posted, I know for certain that Imageshack sends the correct headers with the image. If your script was downloading the images to your own server, and linking to them from there, it's possible that correct header's weren't being sent.Sounds like you're linking straight to Imageshack though (in this example broken image, anyway), so I guess it isn't the MIME type that's causing your problems.
chigley