Here we are going to create a feedback form for you site to allow users contact you.
The script is very simple and this article is for php begginers. we have to follow following steps for that.
Design a Feedback Form
The first thing we need to do is to design the feedback form. following piece code will build a form for you. here i am going to save it in html file say, feedback.html.
<fieldset class=“repeat”>
<legend>Feedback…</legend>
<label class=“preField”>
Name:
<input name=“name” type=“text” />
</label>
<label class=“preField”>Email:
<input name=“email” type=“text” />
</label>
<label class=“preField”>Message:<br />
<textarea name=“message” rows=“8″ cols=“40″>
</textarea></label>
<input type=“button” value=“Submit” onClick=“return vldFrm_Feedback();”/>
</fieldset>
</form>
Basically the form asks a visitor for his Name, email address and message, and presents him with a button which he can click to submit the contents of the form.
When the form is submitted, it is “posted” (see the “method” attribute of the tag) to “sendmail.php”.
Improve look of feedback form
i have apply CSS on above code to improve its look. See look of form below…

You can get greate ideas to apply CSS on forms at http://www.formassembly.com/
and the CSS code is as followes…
form {
padding: 10px;
font-family: ‘Trebuchet MS’, ‘Lucida Grande’, Verdana, Arial, Sans-Serif;
background-color:#F8F8F6;
background-image: url(formBg.png);
border: 1px dotted #878177;
}
fieldset {
margin: 20px 0;
padding: 15px 10px;
background-color:#F4F4F2;
border: 3px double #878177;
}
legend {
padding: 2px 5px;
color: #1C1C1C;
background-color: #FFD;
border: 1px solid #878177;
}
label.preField {
display: block;
padding: 2px;
margin: 0.4em 4px 0 0;
font-weight: bold;
}
</style>
Validating form Input
As user fill form and send it, we are going to validate input to confirm that user not sending a blank form.
on onClick event of submit button we are going to call Javascript function vldFrm_Feedback() to validate our feedback form.
following code will do it for you…
function vldFrm_Feedback(){
var result = true;
var msg=“”;
if (document.frmFeedback.name.value==“”) {
msg+=“Your Name please !\n“;
result = false;
}
if (document.frmFeedback.email.value==“”) {
msg+=“Your Email please !\n“;
result = false;
}
if (document.frmFeedback.message.value==“”) {
msg+=“Your Message is Required !”;
result = false;
}
if(msg==“”){
return result;
}{
alert(msg)
return result;
}
}
</script>
Process the form using PHP
Now all that remains is to code “sendmail.php”. This is made extremely easy by the facilities available in PHP. Type the following code into a file named “sendmail.php”.
$Name = $_POST[‘name’] ;
$email = $_POST[‘email’] ;
$message = $_POST[‘message’] ;
$message1=“You have new feedback from”.$Name.“<br /><br />”.$message.“”;
mail( “youremail@example.com”, “Feedback Form…”, $message1, “From: $email” );
echo‘Thanks You for your feedback…<a href="feedback.html" title="Back to Feedback form…">Back</a>’
?>
Here you change youremail@example.com with email on which you want to get user feedback…
Source code
Download Source code for ‘building Feedback Form with php’
Download
discuss this topic to forum
