我正在使用Pear PHP邮件库发送HTML电子邮件(主要是发送到hotmail)。我正在解决CSS正常运行的问题。在收到消息时,CSS位于消息正文中,并且不应用样式。
代码如下:
$message = "<!DOCTYPE html>
<html>
<head>
<style>
body {
font:12px/1.4em Verdana, sans-serif;
color:#333;
background-color:#fff;
width:700px;
margin:50px auto;
padding:0;
}
a {
color:#326EA1;
text-decoration:underline;
padding:0 1px;
}
a:hover {
background-color:#333;
color:#fff;
text-decoration:none;
}
div.header {
border-bottom:1px solid #999;
}
div.item {
padding:5px 0;
border-bottom:1px solid #999;
}
</style>
</head>
</body>";
// PARSE
$limit = 9;
for($x=0;$x<$limit;$x++) {
$title = str_replace(' & ', ' & ', $news[$x]['title']);
$link = $news[$x]['link'];
$description = $news[$x]['desc'];
$date = date('d-m-Y', strtotime($news[$x]['date']));
$message .= '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
$message .= '<p>'.$description.'</p>';
}
$message .="</body> </html>";
foreach($email_add_arr as $name => $email)
{
$crlf = "\n";
$from = "";
$to = "$name <$email>";
$subject = "News - $date";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "";
$password = "";
// Creating the Mime message
$mime = new Mail_mime();
// Setting the body of the email
$mime->setHTMLBody($message);
$body = $mime->get();
$headers = array (
'From' => $from,
'To' => $to,
'Subject' => $subject,
'MIME-Version: 1.0',
'Content-Type: text/html; charset=ISO-8859-1');
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password
));
$mail = $smtp->send($to, $headers, $message);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
}
任何人都有这方面的经验吗?
谢谢!
答案 0 :(得分:7)
您只能在邮件中应用内联样式。
例如:
<div style="float:left; padding: 10px;">demo</div>
答案 1 :(得分:0)
您只能使用内联CSS。试试这个工具http://beaker.mailchimp.com/inline-css
答案 2 :(得分:0)
@ alvaro的回答是正确的。此外,每个客户端支持的确切资源是http://www.campaignmonitor.com/css/
它致力于
适用于所有相关邮件客户端