PHP: How to send HTML email?



Hello,

I am writing a php code to send email in HTML? Following is the code that I have written. It prints HTML tags as well instead of executing them in HTML mail.


<?php
$txtMsg 
'<b><h1> This is HTML mail</h1></b> This is a HTML body.';

ini_set "SMTP""xy.domain.com" ); 
$mail_to'someone@domain.com';
$mail_from='someone@domain.com';
$mail_sub='PHP HTML MAIL';
$mail_mesg=$txtMsg;

//Check for success/failure of delivery 
if(mail($mail_to,$mail_sub,$mail_mesg,"From: $mail_from"))
echo 
"<br><br>Email Successfully Sent!";
else
echo 
"<br><br>Error Sending Email!";
}

?>

Please help



You need to specify MIME version and content type in your header field of email to be able to send email as HTML as follows:

<?php
$header 
= array(
    
"From: $mail_from",
    
"MIME-Version: 1.0",
    
"Content-Type: text/html"
);
mail($mail_to$mail_sub$mail_mesgimplode("\r\n"$header))
?>

This should work.