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 Page

First, let us create the HTML page that simply contains the contact form. Now we can create
a form with two text fields and and one text area.

Our form looks like this

webmanthra.com

But, let’s start with a very basic form and build our way up to something more complicated
such as what you see above. Here is the code for the form save it as contact.html.

    <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">&nbsp;</td>
<td align="left" valign="top">&nbsp;</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">&nbsp;</td>
<td align="left" valign="top">&nbsp;</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">&nbsp;</td>
<td align="left" valign="top">&nbsp;</td>
</tr>
<tr>
<td align="left" valign="top">&nbsp;</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
called contact.php.

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.

« »