![]() |
![]() ![]() ![]() ![]() |
Home
How to create a website
How to create login in website
How to create feedback form
How to create Ajax website
How to create HTML file
How to create feedback form
Creating feedback form is easy task for developers, but designer find it very difficult. Not to worry, I will show you that how easy it is.
Step 1.Create a form name it as "feedbackform.php" and add fields as you want. Name every field properly. There should not be any duplicate name, every field should have a unique name. form tag should be having post method and action="thankyou.php". Copy the entire name (the name attributes in input tag ) of all the fields in one notepad.
<form name="form1" method="post" action=" thankyou.php" >
<table >
<tr>
<td >Name : </td>
<td><input name="txtName" type="text" /></td>
</tr>
<tr>
<td >Email : </td>
<td><input name="txtEmail" type="text" /></td>
</tr>
<tr>
<td > Phone : </td>
<td><input name="txtPhone" type="text" /></td>
</tr>
<tr>
<td >Your comments : </td>
<td><textarea name="txtComments" ></textarea> </td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" value="Submit" /></td>
</tr>
</table>
</form>
The name attributes of above form are txtName, txtEmail, txtPhone, txtComments
Step 2.The second step is to write a php code for sending form to particular email address with the data feed in the form by user. I will explain you each and every step of how it works. Now let’s start with the process.
Create a file with the name ”thankyou.php”. which we have mention in action of the form tag in step 1. below is the complete code of php for sending mail. Details are explained below the code.
<?php
extract($_POST);
if($txtName !=""){
$to = "technobit@gmail.com";
$subject = "contact from website";
$body = "Name: ".$txtName."<br />";
$body.= "Email Id: ".$txtEmail."<br />";
$body.= "Phone Number: ".$txtPhone."<br />";
$body.= "Comments: ".$txtComments."<br />";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= 'From: Webmaster<technobit@gmail.com>' . "\n";
mail($to,$subject,$body,$headers);
}
?>
Thank you for the feedback we ll get back to you soon
PHP starts with <?php and close with ?> whatever we write inside this tags is consider as PHP code.
extract($_POST); is a php function use to extract the value received from the input fields of form and put it in variables.
For i.e. "txtName" used in the input element of the form can be use as variable after extract($_POST); function, like ".$txtName".
Lets move to next line
if($txtName !=""){ in this line it is checked that the field send is not empty. "!" stands for NOT and "=" stands for EQUAL. Combination of both means NOT EQUAL to empty.
$to = "technobit@gmail.com"; in this line we are setting our email address. you can set any email address you want, to receive your feedback details.
$subject = "contact from website"; this is a subject line of email. Set the subject in that way so that it will be easily recognizable when you receive a mail in you inbox.
$body = "Name: ".$txtName."<br />"; this is a body of the mail. In short the format of the mail you will receive in you inbox. This line contains the name variable.
$body.= "Email Id: ".$txtEmail."<br />"; this line is also the same but there is slight difference between both the lines. Guess what ? yes there is a dot after body variable. Dot in PHP is use to merge two lines. In above line $body containing name value is merged in second line with address value. This way all the data is group in one variable $body.
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers .= 'From: Webmaster' . "\n";
These two lines are called as header of the mail. In this character, senders name and email is set. You will receive the email send by webmaster and email technobit@gmail.com
The last but most important function is mail($to,$subject,$body,$headers); This is a function for sending the mail. All the values are set in this function and mail is send.
Note: this code will not work on localhost. Webserver is needed.
That's all guys and mail is send successfully.
Download files (feedback-sample.rar)
If you have any queries write to us on technobit@gmail.com

| © copyrights sudarshansoft 2009 |




