PHP Script : How To Send Mail With HTML and CSS Style

In this tutorial I will described how to send mail through PHP with HTML tag,Normally when we are using basic mail() function of PHP,Its not included HTML tag.So if You want mail with HTML tag then you need define Header "Content-type:text/html" of email.

We can add css style with html content as well with php mail.The combination of css and html will create a beautiful and nice HTML email with php.

You can also check other tutorial of php mail,

Sample Code To send mail With HTML and CSS style.

$headers .= “MIME-Version: 1.0” . “\r\n”;
$headers .= “Content-type:text/html;charset=iso-8859-1” . “\r\n”;
$headers .= ‘From:’ [email protected] “\r\n”;
$messageBody = ”


foreach($results as $result){
$messageBody .= ”

$messageBody .= ‘

Application NameApplication SiteId

$isSend = mail($to,$subject,$messageBody,$headers);
if($isSend) {
echo “Mail sent on ” . date(‘Y-m-d H:i:s’) .’.’;
}catch (Exception $e){
echo $e->getMessage();

I have added extra headers Content-Type which notify mail services that parse this email as HTML.PHP mail headers are providing options to add optional parameters in php mail() function.You can add From,CC,Bcc and attachment etc suing php mail headers.