Feedback form in PHP

Feed back form is one of the common requirement for any website. Website can have this feedback form to collect the messages from the visitors and post to any email address.

Advantage of Feedback form

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. It is useful for visitors as they need not open or login to their email account to send any message. Visitors away from their home computer or using public computers may not be interested 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 of site admin or to any other address in background without exposing the email of site-admin.

HTML form

Feedback form developed by HTML and then entered data 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.. We will be using PHP email a built-in php function to post mail to site admin.

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";}
This is a very simple email validation, it is better to use php built in filter function to check email address.
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: $headers4n";
$headers .= "From: $headers4n";
$headers .= "Errors-to: $headers4n";
$headers = "Content-Type: text/html; charset=iso-8859-1n".$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.
PHP Mail PHP Mailer class PHP Ajax feedback form
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here





    PHP video Tutorials
    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer