| Let’s start with a very basic contact form for now. Our contact form will span two pages one html page with a form and one php page to send the feedback to mail. |
The HTML PageFirst, let us create the HTML page that simply contains the contact form. Now we can create Our form looks like this
But, let’s start with a very basic form and build our way up to something more complicated |
<form id="contact" name="contact" method="post" action="contact.php"> <table width="400" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="2" align="center" valign="top" class="title"> <h2>Php Contact Form</h2> </td> </tr> <tr> <td width="54" align="left" valign="top" class="title">Name</td> <td width="446" align="left" valign="top"> <input name="name" type="text" class="fields" id="name" /></td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top" class="title">Email</td> <td align="left" valign="top"> <input name="email" type="text" class="fields" id="email" /> </td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top" class="title">Message</td> <td align="left" valign="top"> <textarea name="message" cols="45" rows="5" class="fields" id="message"> </textarea></td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"> </td> </tr> <tr> <td align="left" valign="top"> </td> <td align="left" valign="top"> <input type="button" name="cancel" id="cancel" value="Cancel" /> <input type="submit" name="submit" id="submit" value="Submit" /> </td> </tr> </table> </form> |
| Now we have done the html part of the form, you can now see a form like in the image. Of course, that is just one half of our contact form. So, here is our PHP code. You should place the following code into a new file you create Php Code<?php
if(isset($_POST['submit'])) //use this to check that wether the
form is submited
{
$to = "you@you.com" //edit thie email with your own
$subject = "Php Contact Form forum.webmanthra.com" //subject for
you mail
$name = $_POST['name'] // used to get the value in the name field
$email_field = $_POST['email'] // used to get the value
in the email field
$message = $_POST['message'] // used to get the value in the
message field
$mailcontents = "From: $name\n E-Mail: $email\n Message:\n $message";
mail($to, $subject, $body);
}
?>
<table width="650" border="0" align="center" cellpadding="0"
cellspacing="0">
<tr>
<td align="center" valign="top">
<h2>Thank You.</h2>
</td>
</tr>
</table>
Here is all you need for a php contact form create and upload it to your server then check it. Still confused download the file you no need to waste your time to type the code. |
« Professionally Made Flash Websites Top Free Web Hosting Services | Ultimate Free Web Hosting Plans »
