spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / php / phpemail / 2 To page 1current pageTo page 3To page 4
[previous][next]

Email Forms in PHP

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

The Form

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

Take a look at the code on the next page. It is very typical of any scripting language, server-side or client-side, so if you have any amount of knowledge in JavaScript, ASP, JSP, Perl or the like, it should seem very familiar.

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.

home / programming / php / phpemail / 2 To page 1current pageTo page 3To page 4
[previous][next]


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
UC Gaining a Foothold in Government · Workers Say Telework Is More Productive, Bosses Not So Sure · Kingston Debuts Power-Saving Memory Upgrades


Created: July 30, 2001
Revised: July 30, 2001


URL: http://webreference.com/programming/javascript/phpemail/2.html