Home > PHP > Mail > How to add HTML content in php mail() function

How to add HTML content in php mail() function

In this post i would like to explain about how to add HTML content to PHP mail() function. Few servers are supports PHP mailer class then we can send mails with Sending mails using PHP mailer class . And few servers are not supporting PHP mailer class. For those below function will be useful to send mails with HTML content.

How to add HTML content in PHP mail() function by Anil Kumar Panigrahi

How to add HTML content in PHP mail() function by Anil Kumar Panigrahi

The PHP Code

 

<?php
$to = "[To Address]";
$subject = "Contact Details";

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

// Additional headers
$headers .= 'To: Anil Labs <To Address>' . "\r\n";
$headers .= 'From: Anil Labs <To address>' . "\r\n";
// Additional headers
$email_body = "<table width="721" height="186" border="0" align="left">
  <tr>
    <td colspan="
3" style="background-color:#666666; color:#FFFFFF" align="left"><strong>Contact  - Us </strong></td>
 </tr>
  <tr><td>First Name : </td> <td>:</td> <td>Anil Labs</td><tr>
   <tr><td>Email</td> <td>:</td> <td>To Address</td></tr>
   <tr><td>Subject</td> <td>:</td> <td>".$subject."</td></tr>
   <tr><td valign='top'>Comments</td> <td valign='top'>:</td> <td>test</td></tr>
   
 
</table>";

$message = "
<html>
<head>
<title></title>
</head>
<body ><center>
".stripslashes($email_body)."
</center>
</body>
</html>
";

mail($to,$subject,$message,$headers);

?>
You may also like
Multi-language support for web application with MySql and PHP
How to add or remove file fields using jquery
How to calculate statistics in daily, weekly , monthly and yearly using php
How to rectify json_encode returns null in php web services

3 Responses

  1. Pingback : How to send email using HTML templates in Codeigniter - Anil Labs

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.