Friday, September 20, 2013
HTML FORM MAIL SENDING WITH HTML STRUCTURE AND CSS
Friday, September 20, 2013 by Unknown
Hii, we all sometime in developing needs to send a mail and this task of 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”>
<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”;
{
$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>
“;
<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”;
$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”;
$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....!!!!!!
Originally posted at Mycodestock.
Tags: HTML , PHP
Subscribe to:
Post Comments (Atom)
0 Responses to “HTML FORM MAIL SENDING WITH HTML STRUCTURE AND CSS”
Post a Comment