Email Form Tutorial
- Right click on the below file and choose "Save Target As…" to save it to your computer.
- Rename the file so that it ends in ".php" instead of ".txt". The first part of the filename can be whatever you want, but the file extension must be .php for the form to work.
- The example email form has two input boxes (name and email) and one text area (comments). If you don't want any more fields, then skip to step something.
To add an input box, add the following code after "<table>" and before "</table>". Change all places that say "email".
<td><input type="text" id="email" name="email"></td>
To add a drop down list, add the following code after "<table>" and before "</table>". Change all places that say "gender". Change "Male" and "Female" to whatever you want the choices to be.
<select id="gender" name="gender">
To add a text area, add the following code after "<table>" and before "</table>". Change all places that say "comments".
<td><textarea id="comments" name="comments"></textarea></td>
To change what the "Submit" button says, edit the following part of the code that is in bold.
<td><input type="submit" name="submit" value="Submit"></td>
- Change "firstname.lastname@example.org" to your email address (line 7). This must stay in quotes.
- Change "Email Form Comments" to what you want the subject of the email to be (line 8). This must stay in quotes.
Edit the following part of the code so that it corresponds with the fields you added to the form. You will want to change the places that say "name", "email", and "comments" if you changed the names of these fields.
$message = 'Name: '.$name."\n";
$message .= 'Email: '.$email."\n";
$message .= 'Comments: '.$comments;
If you have more than three fields, add this line after the "comments" line, and change both places that say "gender" to the name of your field.
$message .= 'Gender: '.$gender."\n";
Email Form Examples
Note: This form does not actually send your comments.