Sending Form Results by Email
One easy way to use a form is to send the results by email. You can do this without using any JavaScript, although you could use JavaScript to validate the information entered (as you'll learn later in this hour).
To send a form's results by email, you use the mailto: action in the form's ACTION attribute. Listing 12.2 is a modified version of the name and address form from Listing 12.1 that sends the results by email.
Listing 12.2 Sending a form's results by email
<html> <head> <title>Form Example</title> </head> <body> <h1>Form Example</h1> Enter the following information. When you press the Submit button, the data you entered will be sent by email. <form name="form1" action="mailto:user@host.com" enctype="text/plain" method="POST"> <p><b>Name:</b> <input TYPE="TEXT" SIZE="20" NAME="yourname"> </p> <p><b>Address:</b> <input TYPE="TEXT" SIZE="30" NAME="address"> </p> <p><b>Phone: </b> <input TYPE="TEXT" SIZE="15" NAME="phone"> </p> <p><input TYPE="SUBMIT" VALUE="Submit"></p> </form> </body> </html>
To use this form, change user@host.com to your email address. Notice the enctype=text/plain attribute in the <form> tag. This ensures that the information in the email message will be in a readable format.
While this provides a quick and dirty way of retrieving data from a form, the disadvantage of this technique is that it is highly browser-dependent. Whether it will work for each user of your page depends on the configuration of their browser and their email client.
TIP
For a more reliable way of sending form results, you can use a CGI form-to-email gateway. Several free CGI scripts and services are available. You'll find links to them on this book's Web site: http://www.jsworkshop.com/.