Page 1 of 1

Embedded Images as background of div

Posted: Wed Dec 29, 2010 3:22 pm
by chubby92
Hello everyone.

I was trying to make the embedded image as background of one of my divs >

Code: Select all

$message->setBody(
'<html>' .
' <head></head>' .
' <body>' .
'  <div style="background-image:url(\'' . $cid . '\');background-repeat:no-repeat;width:200px;height:150px;border:1px solid black;">test?</div>' .
'  <img src="' . $cid . '" alt="Image" />' .
' </body>' .
'</html>',
  'text/html' //Mark the content-type as HTML
);
The <img> is working but the div has no background img.
any idea how to make the img as background?

thanks

Re: Embedded Images as background of div

Posted: Tue Jan 18, 2011 6:50 am
by mpetrovich
Note that you do not have the same HTML/CSS power in emails that you have on a Web page. For example, Outlook a few years ago became somewhat primitive when Microsoft chose to use the Word engine to display HTML. So, you cannot rely upon background images in your email. I believe you can use them in table cells, but not DIVs. You can do some testing to confirm this.

Also, note that you cannot use the HEAD and BODY tags in an email. Those are generally stripped away.