SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Feedback form in PHP

Feed back form is very important for any website point of view. Any website can have this feedback form to collect the messages from the visitors and post to any email address. Feedback form developed by HTML and then processing is done by using PHP. Any other CGI or scripting language can be used to post the message from the website to the webmaster. We will discuss PHP feedback form here. By using a feedback form or contact us form the email address need not be exposed to web robots who will pick up the email address for spamming. Visitors away from their home computer or using public computers may not able to post messages with a mailto link. This can be completely avoided by using feedback forms as all the details of the feedback form is posted to email address by using PHP. PHP email function is a built-in php function.

Let us first start with HTML to display the feedback form. You can see the contactus page of this site ( view source ) to get the html code. The detail country list is also available there.
<form method='post' action='contactusck.php'>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" class='topsub' align = center COLSPAN=2>
<B>CONTACT US / FEEDBACK
FORM</B></font></td>
 
</tr>
<tr>
<td width="50%" bgcolor="#8080a6"><font face="Verdana" color="#FFFFFF">&nbsp;Your
First Name</font></td>
<td width="50%" bgcolor="#8080a6">&nbsp;<font color="#FFFFFF" face="Verdana">Your
Last Name</font></td>
</tr>
<tr>
<td width="50%" bgcolor="dfdfdf" >&nbsp;<input type='text' name='fname'></td>
<td width="50%" bgcolor="dfdfdf">&nbsp;<input type='text' name='lname'></td>
</tr>
<tr>
<td width="50%" bgcolor="#8080a6"><font face="Verdana" color="#FFFFFF">&nbsp;Email Address</font></td>
<td width="50%" bgcolor="#8080a6">&nbsp;<font color="#FFFFFF" face="Verdana">Telephone No </font></td>
</tr>
<tr>
<td width="50%" bgcolor="F1F1F1" >&nbsp;<input type='text' name='em'><font color="#FF0000"><B>*</b></font></td>
<td width="50%" bgcolor="F1F1F1">&nbsp;<input type='text' name='telephone'></td>
</tr>
<tr>
<td width="50%" bgcolor="#8080a6"><font face="Verdana" color="#FFFFFF">&nbsp;Address 1</font></td>
<td width="50%" bgcolor="#8080a6">&nbsp;<font color="#FFFFFF" face="Verdana">Address 2 </font></td>
</tr>
<tr>
<td width="50%" bgcolor="dfdfdf" >&nbsp;<input type='text' name='ad1'></td>
<td width="50%" bgcolor="dfdfdf">&nbsp;<input type='text' name='ad2'></td>
</tr>
<tr>
<td width="50%" bgcolor="#8080a6"><font face="Verdana" color="#FFFFFF">&nbsp;City</font></td>
<td width="50%" bgcolor="#8080a6">&nbsp;<font color="#FFFFFF" face="Verdana">State </font></td>
</tr>
<tr>
<td width="50%" bgcolor="F1F1F1" >&nbsp;<input type='text' name='city'></td>
<td width="50%" bgcolor="F1F1F1">&nbsp;<input type='text' name='state'></td>
</tr>
<tr>
<td width="50%" bgcolor="#8080a6"><font face="Verdana" color="#FFFFFF">&nbsp;Country</font></td>
<td width="50%" bgcolor="#8080a6">&nbsp;<font color="#FFFFFF" face="Verdana"> Zip / Pin </font></td>
</tr>
<tr>
<td width="50%" bgcolor="dfdfdf" >&nbsp;<select name="country"><OPTION VALUE=Afghanistan>Afghanistan <OPTION VALUE=Albania>Albania <OPTION VALUE=Zambia>Zambia <OPTION VALUE=Zimbabwe>Zimbabwe</select></td> <td width="50%" bgcolor="dfdfdf">&nbsp;<input type='text' name='zip'></td> </tr> <tr> <td width="50%" bgcolor="F1F1F1" colspan='2' align='center'>&nbsp;<textarea name="dtl" rows="4" cols="40"></textarea></td> </tr> <tr> <tr> <td bgcolor='#F1F1F1' colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'> <input type='submit' value='Submit'> <input type='reset' value='Reset'> </font></td> </tr>   </table> </form>  

This form is posting all the variable to another page contactusck.php and there the visitor entries are validated. You can see the only compulsory requirement for the visitor to fill the email address and other input boxes are optional. You can check the form validation page of this site to get details on how to validate a form.

Now we will process the contactusck.php page to post the details to webmaster's email address.

We will do the PHP email validation to check the user entered email address is in correct format or not

$status = "OK";
$msg="";
//error_reporting(E_ERROR | E_PARSE | E_CORE_ERROR);
if (!stristr($em,"@") OR !stristr($em,".")) {
$msg="Your email address is not correct<BR>";
$status= "NOTOK";}
 

We will check the flag $status to know the status of validation and if passed we will prepare the header of the email address. Then we will use the php email function to send the email. PHP email function takes four parameters.

mail("nobody@aol.com", "the subject", $message, "From: webmaster@$SERVER_NAME\nReply-To: webmaster@$SERVER_NAME\nXMailer: PHP/" . phpversion());

Here is the code we use in our site to send the details.

if($status=="OK"){// echo $query;
$headers="";
$headers4="webmaster@sitename.com"; ///// Change this address within quotes to your address ///
$headers.="Reply-to: $headers4\n";
$headers .= "From: $headers4\n";
$headers .= "Errors-to: $headers4\n";
$headers = "Content-Type: text/html; charset=iso-8859-1\n".$headers;
mail("wemaster@sitename.com,otheraddress@hotmail.com,onemore@yahoo.com","Feedback From plus2net.net","This is the feedback from plus2net.net <BR>
First Name :$fname
<BR>Last Name :$lname
<br>Email Addrss: $em<br>Phone no:$telephone<br>Address1:$ad1<br>Address2:$ad2<br>City:$city<br>
State:$state<br>Country:$country<br>Zip:$zip<BR><BR> <BR> Message Details : $dtl","$headers");
echo "<center>Thank you <br><br> We will contact you soon </center>";
}
 
Thats all. Our feedback form is ready.

Discuss this tutorial at forum


 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.