pTutorial

New way to learn Programming

How To Send Html Mail In PHP

HTML mail in PHP

HTML mail in PHP: You can easily send the HTML mail like the text mail in PHP using mail function by concatenating the complete HTML to the variable like below shown(In my case it's $temphtml).

Note: Content-type header is mandatory for sending HTML email.

HTML mail example

<?php

//Receiever of the mail
$to="info@ptutorial.com";

//subject of the mail
$subject = "Test";

//message with HTML 
$temphtml="
<table width='400' border='1'>
  <tr bgcolor='#CCCCCC'>
    <th>Name </th>
    <th>Email</th>
  </tr>
  <tr>
    <td>Umar</td>
    <td>umar@gmail.com</td>
  </tr>
  <tr>
    <td>Jaideep</td>
    <td>Jaideep@yahoo.com</td>
  </tr>
  <tr>
    <td>John</td>
    <td>John@gmail.com</td>
  </tr>
</table>";


$headers .= "From:info@ptutorial.com";

$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$status=mail($to, $subject, $temphtml, $headers);
if($status){
echo "Email sent successfully.";
}else{
echo "Error occurred.";
}

?>

Output

Email sent successfully.

Explanation

We have created a simple email with HTML template and sent to the email.

See Also


QUOTES OF THE DAY

Knowledge itself is a power.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER