开发者

PEAR MAIL HTML email not well formatted in Hotmail/Yahoo/GMail

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 he开发者_高级运维lp.

$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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜