Email Forms in PHP - (2/4)
Email Forms in PHP
Like any email form, the original form itself is quite simple. No great shakes here, just a standard HTML form with a POST method and the action pointing to the PHP page that will process the form results.
<form name="form" method="post" action="contact_thanks.php"> <p class="bodymd">Your Name<br> <input type="text" name="Name"> </p> <p class="bodymd">Your Email<br> <input type="text" name="Email"> </p> <p class="bodymd">Comments or Questions<br> <textarea name="Comments" rows="5" cols="40"></textarea> </p> <p class="bodymd"> <input type="submit" name="Submit" value="Submit"> <input type="reset" name="Reset" value="Clear Form"> </p> </form>
This form can be .html, .shtml or whatever you choose; the page that the results are handed to, however, must be a PHP page.
Processing the Mail
The code is a combination of validation, and, if validated, the email processor as well. Take a look at the first if statement, it is checking to see if any of the fields are empty. If any one field is, it then opens a form and prints a statement to inform the user that they missed some required field(s).
The statements after that are also simple. "If" statements check each of the individual fields to see if they are empty; if they are empty, the script prints that field again to be filled in (note that the form was already opened above if a field was empty). If it is not empty it then stores the value of that field in a hidden field.
Created: July 30, 2001
Revised: July 30, 2001