views:

330

answers:

2

Hello,

I'm using PEAR to send HTML emails from my website. My email are sent, but they are not formatted according to the CSS when viewed in Hotmail/Yahoo/GMail. When I view them in Windows Live MAil, they look great.

To be more specific, it seems as if non of the CSS is taken into consideration (text format, background images etc.).

Here's the code I use to send the email:

$headers = array('From' => $from, 'Subject' => $subject, 'To' => $to);

require_once 'Mail.php';
require_once 'Mail/mime.php';

$crlf = "\n";

$mime = new Mail_mime($crlf);
$mime->setTXTBody($plainText);
$mime->setHTMLBody($htmlText);

$body = $mime->get();
$headers = $mime->headers($headers);

$mail = Mail::factory("mail");
$send = $mail->send($to, $headers, $body);
if (PEAR::isError($send)) {
    $mail_sent = 0;
}else {
    $mail_sent = 1;
}   

Should I include Content-Type in the header? I've tried but it didn't help.

$htmlText is a variable containing my html. The style is embeded into the HTML (not linked to a CSS file).

If anyone can let me know why my email is not formatted in the web clients, I would be gratefull.

Thanks a lot,

Ziv

+2  A: 

You can only use very simple style rules in mails, and it should be specified inline and not in an embedded stylesheet. You can read a lot of information here:

http://www.anandgraves.com/html-email-guide

PatrikAkerstrand
Thanks for the quick reply, this was very helpfull. I'm still having some problems, but I guess it's all down to trial and error.Thanks again.
Ziv Eylon
+1  A: 

It's best to presume that mail clients only support inline styles and images at the most.

kguest