PDA

View Full Version : html mail sent as plain



solarcom
10-17-2006, 04:05 PM
:confused:

I have a script to send email with html, but when its recieved the email becoimes plain text and looks awful. Here's the code (the varibel "id" is passed from an earlier page)

$result = mysql_query("SELECT * FROM newsletters WHERE id='$id'");
while ($row = mysql_fetch_array($result, MYSQL_BOTH))
{
$subject = $row["name"];
$message = $row["content"];

$wwwtext = ("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><title>$subject</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head><body>$message</body></html>");
}

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: newsletter@' . $_SERVER['SERVER_NAME'] . "\r\n" .
'Reply-To: newsletter@' . $_SERVER['SERVER_NAME'] . "\r\n" .
'X-Mailer: PHP/' . phpversion();

$link = mysql_query("SELECT * FROM users WHERE status='subscribed'");
while ($r = mysql_fetch_array($link, MYSQL_BOTH))
{
$email = $r["email"];
$mail = mail($email, $subject, $wwwtext, $headers);
}

solarcom
10-18-2006, 04:57 AM
I got it. These two links will help anyone else having this problem.

http://www.zend.com/zend/spotlight/sendmimeemailpart1.php

http://www.phpbuilder.com/columns/kartic20000807.php3

I must have gone through about fifty websites (4 days and the loss of my last few black hairs) with tutorials, tips, etc, before I found these which explain boundaries, content description and encoding.