HTML Form mail sending with HTML structure and CSS

Hii, we all know that sending an email form HTML form is very easy but what if we want to send some CSS and HTML Design (like table structure) in the mail . So , in this post I will be explaining how to send a mail with custom CSS and HTML.

CSS and HTML can be added with mail by two methods :

–> By PHP mail() function , and

–> By  Form mail method.

Kindly note that both of the above mentioned methods will work if your site  is live and will not work if your site is on your local server.

Here in this post  I’ll be explaining HTML mails with PHP mail() function.

1. Firstly create  a form-

<form action=”” method=”POST”>

<input type=”text” name=”fname”>

<input type=”text” name=”age”>
<input type=”submit” value=”submit”>

</form>

2. Then on the page on which you are receiving this data , write the code below :

if($_POST[‘fname’])
{
$to = “xyz@example.com”;
$subject = “Form Submission”;

$message = ”
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This is a Form</p>
<table border=1>
<tr>
<td><strong>First Name</strong></td>
<td>”.$_POST[‘fname’].”</td>
</tr>
<tr>
<td><strong>Age</strong></td>
<td>”.$_POST[‘age’].”</td>
</tr>
</table>
</body>
</html>
“;

// Always set content-type when sending HTML email
$headers = “MIME-Version: 1.0” . “\r\n”;
$headers .= “Content-type:text/html;charset=iso-8859-1” . “\r\n”;

// More headers
$headers .= ‘From: <email@example.com>’ . “\r\n”;
//$headers .= ‘Cc: myboss@example.com’ . “\r\n”;

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

The above code send the form data with table structure in a mail.

I will be teaching the same HTML mail functionality with formMail in my next post. Don’t miss it because it is easier then this and mainly used for big forms.

Hope you like this post……..Please Comment…………!!!!!!!!!

Leave a comment