Create a Readable Email Contact Form with PHP Tutorial - no Programming Skills Required
First, create a form. The form must be "post" method with the action "processemailform.php". (We'll get to that file later.)
<form name="form1" method="post" action="processemailform.php">
Create your form by adding the form fields. Name your form fields with the caption you wish to see in your email. For example:
<input name="Favorite Food" type="text" size="50">
will display like this in your email:
NOTE: if you are making the field a "required" field, do not use spaces in the form field caption. For example, use this instead:
<input name="Favorite_Food" type="text" size="50">
You can put the text that the user sees as one thing, and what you will see in the email as another. This makes for better logic flow. For example, in my sample for, I want to know how the visitor found my website. I will ask:
How did you find this tutorial?
But that might not make sense for the person recieving the email. So enter a "name" that is appropriate for the email:
<input name="How this tutorial was found" type="text" size="75">
NOTE: every form field name (except radio buttons) MUST be unique. If you are collecting multiple pieces of the same data, enumerate them in the name field. For example:
<input name="First Pet's Name" type="text" size="30">
<input name="Second Pet's Name" type="text" size="30">
<input name="Third Pet's Name" type="text" size="30">
Or for checkboxes:
<input type="checkbox" name="Tried tutorial 'Email Contact Form'" value="Yes">
Email Contact Form
<input type="checkbox" name="Tried tutorial 'Show and Hide Text'" value="Yes">
Show and Hide Text
Checkbox results will only return if the person filling out the form has checked that box.
NOTE: every radio button form field name MUST be the same for that group. For example:
Do you prefer PHP or ASP for a scripting language?
<input type="radio" name="Scripting language preference" value="PHP" checked="checked">PHP
<input type="radio" name="Scripting language preference" value="ASP">ASP
And in a second radio button group:
Do you prefer Windows or Unix hosting?
<input type="radio" name="Hosting preference" value="Windows" checked="checked">Windows
<input type="radio" name="Hosting preference" value="Unix">Unix
Many contact forms are small and don't collect too much information. But suppose that yours does, or that you are building a registration form of some sort. What makes so many emailed forms unreadable is having every form field listed one line after another, with no breaks or separation. Gloucester Web Designs has a great solution.