tags:

views:

30

answers:

1

I have a mail function, and it works fine, I get mails. But the problem is that I also get the HTML tags as it is. I have code as follows:

$from=$_REQUEST['id'];  
$to  = '[email protected]';  

$headers .= 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  

$headers = "From: $from \r\n" .  
    "Reply-To: $from \r\n" .  
    "X-Mailer: PHP/" . phpversion();  

$subject="Contact Mail has received";  

$message=" SOME HTML TAGS ";

Inside the message body, I have HTML tags like table, tr, td, etc. But when I receive the mail, I don't get the table. I get all the HTML tags as table, tr, td. In header, I have even specified content type as text/html, but still I have the same issue.

How can I avoid this?

+3  A: 

You haven't specified text/html because you are overwritting you headers!

Here, you assign it then overwrite it:

$headers .= 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  

$headers = "From: $from \r\n" .  
       "Reply-To: $from \r\n" .  
       "X-Mailer: PHP/" . phpversion();  

It should be

$headers .= 'MIME-Version: 1.0' . "\r\n";  
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";  

$headers .= "From: $from \r\n" .  
       "Reply-To: $from \r\n" .  
       "X-Mailer: PHP/" . phpversion();  

You missed a dot to append more headers. This overwrites your Content-Type and that is why it is parsing the email as text and not has HTML

Bob Fincheimer