Sending Form Results by Email
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:firstname.lastname@example.org" 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 email@example.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.
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/.