Embedded Images as background of div

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
chubby92
Forum Newbie
Posts: 1
Joined: Wed Dec 29, 2010 3:19 pm

Embedded Images as background of div

Post 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
mpetrovich
Forum Commoner
Posts: 55
Joined: Fri Oct 19, 2007 2:02 am
Location: Vancouver, WA, USA

Re: Embedded Images as background of div

Post 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.
Post Reply