Sending Form Results by Email
By Michael Moncur (October 13, 2003)
The ACTION attribute of a <form> tag tells the browser where to send the data from the form. While the value of this attribute is usually the URL of a CGI script, you can also use a mailto: URL to send the results by email. The following <form> tag demonstrates this:
<form action=mailto:firstname.lastname@example.org method="POST"
This <form> tag includes the following key attributes:
The trouble with using this method to send form results is that it is highly dependent on the browser in use and the email client in use. In particular, some of the most popular versions of Internet Explorer will not work correctly. With all of the browser troubles, you're likely to lose about half of your readers' messages.
One of the most popular scripts is formmail.pl, written in Perl. However, some versions of formmail have major security holes and have been exploited by spammers. Use only the following fixed versions from their official source:
For PHP, you can write your own form-to-email program easily or use one of the many available for free:
You can also use many remotely-hosted services to send your form results without any code on your own server. There is a list of these services here:
As one of the most commonly-needed features, it's a shame this particular aspect of HTML forms hasn't been standardized or well supported by browser makers. But even if current browsers improve, your best bet for a reliable email gateway is to use a server-side approach.
(c) 2003-2005 by Michael Moncur. All rights reserved. No content may be reproduced without explicit consent.