Php

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 and send using 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,

Related Post

Sample Code To send mail With HTML and CSS style.

$to = aa@gmail.com;
$subject = "Expired access token of Facebook";
$messageHed = '

<i>Dear Admin,
        The Facebook Application Token will expire next couple of days.
        Please, Login and regenerate access token.</i>
';
$headers='';
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From:' .par@gmail.com. "\r\n";
$messageBody = "
<div class="topHeader">
<div class="logo"> <img src="". IMGESPATH ."a_logo.png" alt="abcLogo"></div>
</div>
<div>".$messageHed."</div>
<div class="datacontainer">
<div class="Data_table">

";
foreach($results as $result){
$messageBody .= "

";
}
$messageBody .= '
<table cellpadding="0" cellspacing="1" border="0" width="100%" bgcolor="#fff">
<tbody>
<tr>
<th align="left">Application Name</th>
<th align="left">Application SiteId</th>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>".$result['Name']."</td>
<td>".$result['ApplicationSiteId']."</td>
</tr>
</tbody>
</table>
</div>
</div>
';
try{
$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.

View Comments

Recent Posts

Configure and Retrieve S3 Information Using Laravel PHP-AWS-SDK

This tutorial helps integrate a PHP SDK with Laravel. We'll install aws-php-sdk into laravel application and access all aws services… Read More

4 months ago

What is the Purpose of php_eol in PHP?

in this quick PHP tutorial, We'll discuss php_eol with examples. PHP_EOL is a predefined constant in PHP and represents an… Read More

10 months ago

Laravel Table Relationship Methods With Example

This Laravel tutorial helps to understand table Relationships using Elequonte ORM. We'll explore laravel table Relationships usage and best practices… Read More

10 months ago

Exploring the Power of Laravel Eloquent Join?

We'll explore different join methods of Laravel eloquent with examples. The join helps to fetch the data from multiple database… Read More

10 months ago

Quick and Easy Installation of Laravel Valet

in this Laravel tutorial, We'll explore valet, which is a development environment for macOS minimalists. It's a lightweight Laravel development… Read More

11 months ago

What is Laravel Soft Delete and How Does it Work?

I'll go through how to use soft delete in Laravel 10 in this post. The soft deletes are a method… Read More

11 months ago

Categories