I'm using the Pear PHP mail library to send HTML emails (mainly to hotmail). I'm having issues with the CSS functioning correctly. At the moment when the message is received the CSS is in the body of the message and the styles are not applied.
The code is as follows:
$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>");
}
}
Anyone have any experience with this?
Thanks!