Email Form Tutorial

  1. Right click on the below file and choose "Save Target As…" to save it to your computer.
  2. 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.
  3. 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.
  4. To add an input box, add the following code after "<table>" and before "</table>". Change all places that say "email".
    <tr>
        <td><label for="email">Email</label></td>
        <td><input type="text" id="email" name="email"></td>
    </tr>
  5. 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.
    <tr>
        <td><label for="gender">Gender</label></td>
        <td>
            <select id="gender" name="gender">
            <option>Male</option>
            <option>Female</option>
            </select>
        </td>
    </tr>
    To add another option, add the following code after the "Female" line and before the "</select>" line and change "Unspecified" to the option name.
    <option>Unspecified</option>
  6. To add a text area, add the following code after "<table>" and before "</table>". Change all places that say "comments".
    <tr>
        <td><label for="comments">Comments</label></td>
        <td><textarea id="comments" name="comments"></textarea></td>
    </tr>
  7. 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>
  8. Change "yourname@example.com" to your email address (line 7). This must stay in quotes.
  9. Change "Email Form Comments" to what you want the subject of the email to be (line 8). This must stay in quotes.
  10. 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;
  11. 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.