4 Replies - 6356 Views - Last Post: 17 April 2009 - 11:52 PM Rate Topic: -----

#1 ninethousandfeet@msn.com  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 310
  • Joined: 09-February 09

Can I use div tags in php mail()?

Post icon  Posted 16 April 2009 - 08:44 PM

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:
#emailLogo {
	background: url(Images/logo.jpg);
}


php:
$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 www.mysite.com.</p>
<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);



Is This A Good Question/Topic? 0
  • +

Replies To: Can I use div tags in php mail()?

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,383
  • Joined: 10-May 07

Re: Can I use div tags in php mail()?

Posted 16 April 2009 - 08:53 PM

I'm pretty sure that you can't include the css file in the email. You would need to link it in the header & use fully qualified domain name urls.
Was This Post Helpful? 0
  • +
  • -

#3 liyam  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 5
  • Joined: 16-April 09

Re: Can I use div tags in php mail()?

Posted 17 April 2009 - 12:57 AM

you can't include the CSS file in the email. you just have to embed it in the head tag. actually, it's a bad practice to use CSS based layout as there are some e-mail clients that does not fully support CSS.

read this to have a better idea on how to do HTML version emails:
http://www.sitepoint...il-newsletters/


what you can actually do for your logo to show up is to embed the image in the e-mail using CID embedding

This post has been edited by liyam: 17 April 2009 - 01:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 SpaceMan  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 10
  • View blog
  • Posts: 507
  • Joined: 20-February 03

Re: Can I use div tags in php mail()?

Posted 17 April 2009 - 05:02 AM

you can use mail function, but need to mime.

this is one i use, mostly. will use direct connection to mail server, is much better the php mail function.

but i think it does that also. i do have a mime class for the mail function if that is what you prefer.

PHPMailer
Full Featured Email Transfer Class for PHP
==========================================

http://phpmailer.sourceforge.net/
Was This Post Helpful? 1
  • +
  • -

#5 Hary  Icon User is offline

  • D.I.C Regular

Reputation: 44
  • View blog
  • Posts: 427
  • Joined: 23-September 08

Re: Can I use div tags in php mail()?

Posted 17 April 2009 - 11:52 PM

Just use PHPMailer, it is way more flexible and better.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1