Page 1 of 1

Can I add div tag to my mail()?

Posted: Thu Apr 16, 2009 10:46 pm
by ninethousandfeet
hello,

this might be more related to css, but i figured that i would start here... i am trying to add my logo to my mail(). i would like to add a <div> and have the image coming from my css style sheet. reason being that i have noticed many mail hosts make users accept images in order for them to display and it also seems to make the mail more prone to end up in the spam/junk folder for some reason.

i've got this, but the image is ignored in my mail()... any ideas? is it possible? thank you!
css:

Code: Select all

 
#emailLogo {
    background: url(Images/logo.jpg);
}
 
php:

Code: Select all

 
$email = $row_getALLemails['email'];
$comment = $row_getALLemails['comment_title'];
$subject = "New comment";
$message = "
<head>
<title>mysite</title>
</head>
 
<body>
<div id ='emailLogo'></div>
<h3>Hello, $username!</h3>
<p>You have a NEW comment in this conversation: </p>
<h4>$comment</h4>
<p>Login at http://www.mysite.com.
<p>Click the conversation topic to view, discuss, and share!</p>
<p>Thank you,<br />
  the mysite community</p>
<p>--This is an automated response, please do not reply--</p>
</body>
</html>
";
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'Content-type: image/jpg;' . "\r\n";
$headers .= 'From: mysite <me@mysite.com>';
mail($email, $subject, $message, $headers);
 

Re: Can I add div tag to my mail()?

Posted: Thu Apr 16, 2009 10:50 pm
by requinix
So where'd you put the CSS? I don't see it in the email.

And why can't you use an <img>?

Re: Can I add div tag to my mail()?

Posted: Fri Apr 17, 2009 2:40 pm
by ninethousandfeet
the css id is listed there in the first section and then the div tag with the css is on line 11 of the php code. i wanted to see if i could get an image onto the page in a different way because i've read that a lot of email clients do not allow images to automatically show up and some of them send the mail to junk/spam if there is an image attached.

any ideas?

Re: Can I add div tag to my mail()?

Posted: Fri Apr 17, 2009 3:25 pm
by requinix
There's two parts to CSS: the actual definition of the stuff and how you put references to it inside the HTML document. It won't work unless you do both parts.

You did not do both parts. You need a <style> block inside the <head> defining the styles.

And if a client would block based on images then it'll block background images too, so it doesn't really matter and you should just use an <img> like everybody else.

Re: Can I add div tag to my mail()?

Posted: Sat Apr 18, 2009 1:37 pm
by ninethousandfeet
sounds good. i'll stick with the image tag. thanks for the help.