[Readymade script] A feedback/contact form for your website

You can use this form to allow your visitor contact you for enquiries or feedback. you don’t have to give out your email address so that people wont spam you.

Step 1: The script. It has two parts:
1. The feedback form which is to be filled by the visitor. It is in plain HTML. It will contain necessary variables such as ‘From’, ‘subject’, ‘message’.
2. The PHP script which would be hosted on your server. This script will process the variables in the feedback form and send the email.

The HTML form:
Copy below code and save it in a file named as feedback.html. When a visitor clicks on fedback link, he should be taken to feedback.html
Code:
<form method=”POST” action=”/feedback.php”>
<table border=”0″ cellpadding=”0″ width=”63%” cellspacing=”0″>
<tr>
<td width=”23%”>Your email address:</td>
<td width=”77%”> <input type=”text” name=”from” size=”40″></td>
</tr>
<tr>
<td width=”23%”>Subject of mail: </td>
<td width=”77%”> <input type=”text” name=”subject” size=”40″></td>
</tr>
<tr>
<td width=”23%” valign=”top”>Your message:</td>
<td width=”77%”> <textarea name=”body” rows=”7″ col=”20″ cols=”34″></textarea></td>
</tr>
<tr>
<td width=”23%”> </td>
<td width=”77%”>
<input type=”submit” value=”Send feedback”>
</td>
</tr>
</table>
</form>

The PHP script:
Copy below code and save in a file named feedback.php
Code:
<?php
$to=”youruserid@yourdomain.com”;
$subject= $_POST[‘subject’];
$body = $_POST[‘body’];
$headers= $_POST[‘from’];

if(mail($to,$subject,$body,”From: $headers”))
{
echo “Thank you for your valuable feedback”;
}
else
{
echo “Oops, there seems some problem with sending the feedback. Please try again later. If problem persists, you may send your feedback directly to $to.”;
}
?>

You MUSt replace youruserid@yourdomain.com with your email address.

Step 2: Now upload both the files to your server. You will have to change the relative path of the feedback form if you are not uploading the two giles to the same directory.

Step3: Format the elements as per your needs.

Personal notes:
If your host does not support PHP, you can signup for free PHP hosting at http://www.x10hosting.com or similar site. If you will do so, you MUST change the action attribute of the HTML form to absolute URL such as http://www.username.x10hosting.com/feedback.php
References:
Adopted the PHP mail function from http://www.freewebmasterhelp.com/tutorials/php/5. Please note that there seems some problem with sequence of variables used there. I have used the correct sequence after trial and error.

Source

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s