我正在使用 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>");
}
}
有人对此有经验吗?
谢谢!