PHP - FeedBack Form
This WDS will be the base for my CIT-235 class presentation on PHP FeedBack Forms.
Until today, I had the link "Contact us" in the footer section of this web site as a "mail to:" link. It really bothers me when I visit a website and I want to send an e-mail to whoever is in charge of it and I click on the “contact us” link and the Outlook Express new e-mail screen shows up, or even worse, if I’m not using my personal computer, It asks me to set up a new account on Outlook Express. It frustrates me… It takes a lot of my time to get rid and close all the new screens and I won’t be able to send the e-mail unless I do all the work myself by looking at the status bar when I hove over the “Contact Us” link and write down the e-mail that appears. Then I have to go to my own e-mail provider, login, start a new message and send the e-mail. So guess how many times I did send an e-mail to a web site that had a “mail to:” link… NONE!!! And I’m sure I’m not the only one.
So, you may ask, why in the world did I have the “Contact Us” link in my own web site setup with the “mail to:” link? The answer is simple: BECAUSE I DID NOT KNOW HOW TO SET UP A FORM.
Until today…
In the next few paragraphs I’ll try to show you how to setup a simple feedback form in PHP that you can use in your own website using dream weaver. We will follow the same steps found in the book: “The Essential Guide to Dreamweaver CS3 with CSS, Ajax and PHP”.
First, start by creating a new PHP file. Then, create a form by clicking in the form button in the forms tab.

This will insert the opening and closing <form> tags. Also, add the following items from the same tab:
- Text Field for the User’s name;
- Text Field for the User’s e-mail;
- Text Area for the User’s comments;
- Button to submit the form;
Make sure that the form is set to POST, since it is a more secure way to submit the information and that the button is set to Submit Form.
You can use CSS to style he form as you prefer. I used the one given by the book.
form {
width:600px;
margin:15px auto 10px 20px;
}
label {
display:block;
font-weight:bold;
}
textarea {
width:400px;
height:150px;
}
.textInput {
width::250px;
}
Your form should look similar to this:

To create the PHP scripting that will send the e-mail we have to understand how to structure the code so we can write it.
To send an email with PHP, we will use the mail() function, which takes up to five arguments, all of the strings, as follows:
- The address of the recipient;
- The subject line;
- The message body;
- A list of other email headers;
- Additional parameters;
First, in order to make sure that the form has been submitted, insert the fallowing code right above and outside the form you created:
<?php
if ($_POST && !$mailSent) {
?>
<p class="warning">Sorry, there was a problem sending your message.</p>
<?php
}
elseif ($_POST&& $mailSent) {
?>
<p>Your message has ben sent. Thank you for your feedback.</p>
<?php }
?>
This will let the user know if the form has been submitted or not.
Now insert the following code right above the DOCTYPE declaration to make up for the five arguments that we discussed previously:
<?php
if (array_key_exists('send', $_POST)) {
//mail processing script
$to = 'your@email.com';
$subject = 'Feedback from YourSite.com';
//process the $_POST variables
$name = $_POST['fdb_name'];
$email = $_POST['fdb_email'];
$comments = $_POST['fdb_comments'];
//build the message
$message = "Name: $name\n\n";
$message .= "Email: $email\n\n";
$message .= "Comments: $comments";
//limit line length to 70 chars
$message = wordwrap($message, 70);
//send it
$mailSent = mail($to, $subject, $message);
}
?>
I hope you found this helpfull.
Here is an example of my own feedback form - Contact Us
Tuesday, December 9, 2008 6:11 PM

