sending email with html content



Hi guys,

I am trying to use html code as content of the email i sending out by using php but why the email my friends received are all in text format ???

what should i do to make my html code works in an email... i have created a html file and want to send it out as newsletter.. what i did is copy all the html code from the file and paste it as value for $contents but this doesn't seem to work.,,

please advise what i suppose to do,, is it i missed some header ??

// connect to db code.. 

$to = "{$row['email']}\r\n";
//$from= "From: $name < $email >\r\n";
$from= "From: testing while< myemail >\r\n";
$subject ="$subject\r\n";

if($mailtype != "html")
	$MailText = stripslashes($MailText);

$contents ="$MailText";

Like setting your From address, you need to set Content-type to text/html.

So, you would do (Example):

// Check if the form was submitted

// Get the subject and message from the form
$subject = $_POST['subject'];
$contents = $_POST['contents'];

// Get date/time
$date = date("y-m-d H:i:s");

// Making the user email address (to send to)
$to = $_POST['name'] . " <" . $_POST['email'] . ">";

// Creating header information
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";	
$headers .= "Reply-To: admin <>\r\n"; 
$headers .= "X-Mailer: PHP/" . phpversion();
$headers .= "From: admin <>\r\n";

// html message
$message = '
   <title>' . $subject . '</title>
   <table width="100%">
         <td>' . $contents . '</td>

// Send email
$mail = mail($to, $subject . ' - ' . $date, $message, $headers);

// Prints a message depending on the sent email status
$mail ? echo 'Email sent !' : echo 'Error sending email !';



Hi guys,

now it can shows the html page after i added the headers (after refer to complex email part from

i have another problems now.. i am wondering why when i viewed the email, the html page displayed on my mailbox looks different from the online version ???
problem i encountered :
- some part of the page colors are different from the online page.,. for instance, a cell suppose to be yellow color but it displayed green in my mailbox
- some of the textfield contain unwanted values such as \"submit \", \"login\" and etc.. the textfields value should be empty but how come there are values with slashes there ??

when i add stripslashes function for my content, i would not able to view the html page (only text displayed),, but if i dun add this function, i am not able to view the proper html page..

please advise what i suppose to do,, thanks.

$from= "From: testing while< myemail >\r\n";
$subject ="$subject\r\n";

if($mailtype != "html")
	$contents = stripslashes($MailText);
$contents ="$MailText";
$from .= "MIME-Version: 1.0\r\n";
$from .= "Content-type: text/html; charset=iso-8859-1\r\n";

Please visit to unsubscribe from the mailing list. Thank you. 

	echo ' email is sent to :';
	echo "<br>".$row['email']."<br>";
Most email apps aren't designed to do fancy html so that might be the problem. Try using CSS and include it inline into your email.