homepage Welcome to WebmasterWorld Guest from 54.167.75.155
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
images and 'mail'
Mr_Cat




msg:4424839
 11:39 pm on Mar 4, 2012 (gmt 0)

Any idea why this code won't work?

Most of it works but I can't get the image to display in the recieved email no matter what I do...


<?php
include ($_SERVER 'DOCUMENT_ROOT'] . "/verify.php"); // this sets up $member_email

$to = $member_email;
$from = "me@website.com";
$subject = "Test Mail from me";

$message = "
<html>
<body bgcolor='#DCEEFC'>
<div align='center'>

<img src='http://www.website.com/gfx/img.png' width='233' height='94' alt='alt text' border='0' />

<b>This is an HTML email.</b> <br>
<font color='red'>Good stuff!</font> <br>
</body>
</html>";
//end of message

$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-Type: text/html\r\n";
$headers.= "From: $from\r\n";
mail($to, $subject, $message, $headers);

echo "Message has been sent!";

?>


No matter what I do I just get a box of the right size containing the alt text in the resulting email. grr.

Additional; I've just discovered the image comes through perfectly on my iphone, but not on gmail via IE...

Any thoughts more than welcome as per usual! Haven't tested it on any other email systems yet

 

incrediBILL




msg:4424863
 3:02 am on Mar 5, 2012 (gmt 0)

Most email, gmail included, blocks loading images unless you give it permission.

Do you get the message about clicking to load images?

Mr_Cat




msg:4424983
 10:04 am on Mar 5, 2012 (gmt 0)

No, that's the weird thing, if I right click and select 'show picture' it still worn't work. I'm not getting the bg colour either. I guess it can't be the code as my phone shows it all fine, but it's very annoying.

FB manage to make their emails look very graphical before you even click to display images.

Any other thoughts?

omoutop




msg:4424985
 10:11 am on Mar 5, 2012 (gmt 0)


Additional; I've just discovered the image comes through perfectly on my iphone, but not on gmail via IE...

Can you try with jgp image? Some older versions of IE have issues with png format

rocknbil




msg:4425104
 4:27 pm on Mar 5, 2012 (gmt 0)

Precisely . . . a mail client is not the same as a web browser. But if it's gmail, yeah, it won't show unless you allow it . . . also be absolutely sure the URL is correct.

Have you visited the image before on your iPhone? Entirely possible it's cached and that's the only reason it works there . . .

Other than that, it's also possible your server is just not serving up the image, or serving it fast enough.

An aside, your email HTML is missing a closing </div>, but that shouldn't have anything to do with it. Maybe it doesn't recognize the xhtml syntax? ( />) Also unlikely, but mail can be fussy.


FB manage to make their emails look very graphical before you even click to display images.


View source of the FB email itself - might be using background images for a lot of it. (?)

Mr_Cat




msg:4425157
 6:17 pm on Mar 5, 2012 (gmt 0)

Well, I've set up outlook express to test things further, that gets the image too once you click 'download images', and the bg colour.

I'm still niffed tho because most people use gmail online which is the only thing that has totally failed on me.

I've tried changing it to jpg but no joy, same thing happens, and what makes me more suspicious is that the bg colour specified doesn't show up either, tho it does on iphone & outlook express so far tested. So this won't help in using bg images for any of it.

By the by I did try looking at the source for an FB email but couldn't access it. If you click 'view source' on gmail via IE you just get;

<!DOCTYPE html><html><head></head><body><div></div></body></html>

and I can't find any way to view source in outlook...

Surely it can't be that tricky :s

Here's the total full code again, I realised I deleted the closing div tag mentioned by accedent purely in my post here.



<?php

include ($_SERVER['DOCUMENT_ROOT'] . "/verify.php"); // this sets up $member_name

$to = $member_email;
$from = "me@website.com";
$subject = "Test Mail from Me";

//begin of HTML message
$message = "
<html>
<body bgcolor=\"#DCEEFC\">
<div align='center'>

<img src='http://www.website.com/gfx/img.jpg' width='233' height='94' alt='alt_text' border='0'>

<br /><b>Rock! This is an HTML email.</b> <br />
<font color='red'>Thanks Groover!</font> <br />
<a href='http://www.website.com'>Let the people Rule</a><p></p>
</div>
<p>Now I can send HTML Email <br /> Regards</p>
<br />Me<br />
</body>
</html>";
//end of message

// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-Type: text/html\r\n";
$headers.= "From: $from\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]email@website.com[/email]";
//$headers .= "Bcc: [email]email@website.com[/email]";

// now lets send the email.
mail($to, $subject, $message, $headers);

echo "Message has been sent!";

?>



Again I borrowed this code instead of writing it from scratch so don't know it all thoroughly, the only bit that doesn't seem clear given a gap in my knowledge is the $headers but it's all pretty simple and obvious, I'm asuming if it could be anything to do with them then someone would have said something already :)

Cheers

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved