douzhan1935
2010-01-24 20:18
浏览 204
已采纳

PEAR MAIL HTML电子邮件在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 = "
";

$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

图片转代码服务由CSDN问答提供 功能建议

我正在使用PEAR从我的网站发送HTML电子邮件。 我发送了电子邮件,但它们没有格式化 根据在Hotmail / Yahoo / GMail中查看时的CSS。 当我在Windows Live MAil中查看它们时,它们看起来很棒。

更具体地说,似乎没有考虑CSS(文本格式,背景图像等) 。

以下是我用来发送电子邮件的代码:

  $ headers = array('From'=> $ from,  'subject'=> $ subject,'To'=> $ to); 
 
require_once'Mail.php'; 
require_once'Mail / mime.php'; 
 
 $ crlf =“
”  ; 
 
 $ 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; 
} 
 <  / code>  
 
 

我应该在标题中包含Content-Type吗? 我试过但它没有帮助。

$ htmlText是一个包含我的html的变量。 该样式嵌入到HTML中(未链接到CSS文件)。

如果有人可以让我知道为什么我的电子邮件没有在Web客户端中格式化,我将不胜感激。< / p>

非常感谢,

Ziv

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • drhqkz3455 2010-01-24 20:23
    已采纳

    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

    评论
    解决 无用
    打赏 举报
  • 查看更多回答(1条)

相关推荐 更多相似问题