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


$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">
    <td colspan="
3" style="background-color:#666666; color:#FFFFFF" align="left"><strong>Contact  - Us </strong></td>
  <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>

$message = "
<body ><center>



Anil Kumar Panigrahi

With more than 10 years experience in PHP and Founder of Anil Labs, a blog for PHP and related posts. contributed posts regarding CodeIgniter, CakePHP and Learn PHP online ... Contact : [email protected]

You may also like...

3 Responses

  1. Thanks a lot man, This was really so Helpful, Thanksssssss

  1. December 7, 2017

    […] how to send email using HTML templates in Codeigniter, earlier post we learned how to send mails using HTML content and using phpmailer and gmail. Now we learn how to send mails in Codeigniter. By follow the below […]

Leave a Reply

Your email address will not be published. Required fields are marked *

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