Generate Directed Traffic to your Website
Form-mail WWW form to e-mail gateway
Introduction
form-mail.pl is a light-weight perl script that takes input from a web form using CGI (Common Gateway Interface), performs some basic analyses on the input data to check its validity before packaging it and sending it to the recipient using the local mailer application on your webserver.
Copyright and Header
|
| form-mail | Version 0.91 |
| Copyright 2005-2006 Dyfed Lloyd Evans | dyfed@celtnet.org.uk |
| Created 08/10/2005 | Last Modified 20/02/2002 |
| Nemeton Information: | http://www.celtnet.org.uk/ |
|
COPYRIGHT NOTICE:
Copyright 2005 – 2006 Dyfed Lloyd Evans, all rights reserved.
The form-mail.pl script may be used and modified free of charge by anyone as long as this copyright notice and the comments above remain intact. By using this code you agree to indemnify Dyfed Lloyd Evans from any liability that might arise from its use.
This code is released under the GPL license. Selling the code for this program without the prior written consent of the author is expressly forbidden. Obtain permission before redistributing this software over the Internet or in any other medium. In all cases copyright and header must remain intact.
If you find this code useful and employ it for your own site, please include a link to this page http://www.celtnet.org.uk/info/form-mail.html on your links page.
Overview:
Functionally, form-mail is an universal web-form to e-mail gateway application. It is (I hope) easy to configure with three settings in the script that need to be changed to suit your own system. Though the script itself was produced to work with the minisite template provided here it should be easy to modify for use with your existing forms as it only needs name, email and comments as input fields. The script also accepts parameters from three hidden input fields subject which specifies the form that calls the script so that you can call the form-mail.pl script from several forms and know precisely which one the user employed to contact you. The other hidden form inputs are formpage which specifies the location of the calling form so that the script can re-direct to it if one of the inputs is mis-formed or missing and redirect that specifies the page to which the script should re-direct after successful completion.
Getting the Code:
The form-mail.pl code is available from this link to a form-mail zipfile that includes the application, the GPL license and a README file specifying how to install the script. If you want to see how this script interacts with a form then you can download the site_example zipfile which includes the form-mail.pl as well as templates for setting-up your own adsense minisite. In this package the template form page is: contact.html.
Between the README files, the code itself (which is extensively annotated) and the various web page templates you should have more than enough information to install the form-mail.pl on your own site.
Brief Instructions on Using the form-mail.pl Script:
The form-mail.pl script has been written in such a way that it does not have to be extensively configured in order to work. Indeed, there are only four variables in the perl file that you will need to define.
| | |
| | #!/usr/bin/perl |
| | This top line of the perl script must point to the location at which your perl interpreter is installed (/usr/bin/perl is the usual location but your system may be configured differently). |
| |
| | $mailprog = '/usr/sbin/sendmail -i -t'; |
| | This variable define the location to your server's mailer program (for most UNIX systems this will be sendmail which is most often located at /usr/lib/sendmail though locations do vary). If this variable is not set correctly, form results will not be mailed to you. Specifying the parameters in this variable is new as of version 0.91, and the -i parameter has been included so to prevent a single period on a line itself from ending a message (the UNIX default). |
| |
| | @referers = ('celtnet.org.uk','YOUR_IP'); |
| | This array allows you to define the precise domains on forms are allowed to reside and which can communicate with form-mail.pl. If a user tries to communicate with form-mail form another server, (ie which is not celtnet.org.uk) they will receive an error message when someone tries to fill out their form. By placing your own domain (www.celtnet.org.uk for example) in the @referers array, this also allows www.celtnet.org.uk, ftp.celtnet.org.uk, any other http address with celtnet.org.uk in it and celtnet.org.uk's IP address to access this script as well, so no users will be turned away.
NOTE: This is not a security check. Referrer headers can EASILY be faked. Rather, it prevents someone on azy_notme.com from using the form-mail on your server to process forms on their server on a regular basis. The real security in this script is based in its simplicity. Users can mail to you and you only.
|
| |
| | $recipient = 'webmaster@celtnet.org.uk'; |
| | This variable specified precisely whom the mail should be sent to. This is the primary security device in the script, allowing the mail to be sent to a single recipient only. It is also hard-coded in the script so that it cannot be modified by an external application or an automated system.
|
|
How it Works:
After receiving input from the form the script first checks that the name, e-mail and comment filled in. If any of these is empty the user is returned to the form to try again. The script also checks that the name does not contain any unusual characters and checks that the e-mail contains both an at-sign (@) and at least one period (.) otherwise the user informed that the name or e-mail address is mal-formed and are returned to the input form to try again. If all the details appear correct the user is briefly shown a page thanking them for commenting on the site and they are then re-directed to a web page (which you can specify).
Form Configuration:
The action of your form needs to point towards this script (obviously), and the method must be POST or GET in capital letters. Below is a list of form fields you can use and how to implement them (there are three visible form fields and three hidden form fields).
Necessary Visible Form Fields
There are three visible form fields that you must have in your form, for form-mail to work correctly:
| Field: | name |
| Description: | This user-filled form field specifies the name of the person sending you the message. This information is placed in the mail header. Only minimal checking of this is done.
|
| Syntax: | <input type=text name="name"> |
|
| Field: | email |
| Description: | This user-filled form field allows the user to specify their return e-mail address. This is included in the header of the mail message that is sent to you. If you want to require an email address with valid syntax, add this field name to the required field.
|
| Syntax: | <input type=text name="email"> |
|
| Field: | comments |
| Description: | This user-filled form field allows the user to type-in the text of the message that they want to send to you. No checking is done on the contents, save that it cannot be empty.
|
| Syntax: | <input type=textarea rows="12" name="comments" wrap="virtual"> |
|
Necessary Hidden Form Fields
There are three hidden form fields that you must have in your form, for form-mail to work correctly:
| Field: | subject |
| Description: | This static field was originally written to specify the region of the website calling the perl script (eg [celtnet_cancer] Contact Form. However, you can specify any text you want for this (or you can specify nothing at all).
|
| Syntax: | <input type=hidden name="subject" value="[celtnet_cancer] Contact Form"> |
|
| Field: | redirect |
| Description: | This static field defines the URL to which the form page should be directed on successful data submission. This could be anywhere in your site, though I generally point this to a home page or a section home page.
|
| Syntax: | <input type=hidden name="redirect" value="http://www.celtnet.org.uk/"> |
|
| Field: | formpage |
| Description: | This hidden static field defines the location of the form that calls the mailer script so that if an error occurs the user can be re-directed back to the form.
|
| Syntax: | <input type=hidden name="formpage" value="http://www.celtnet.org.uk/info/site_example/contact.html"> |
|
Optional Hidden Form Fields
| Field: | required |
| Description: | This field is used to force certain fields in your form to be filled in before the user can successfully submit the form. Simply place all field names that you want to be mandatory into this field. If the required fields are not filled in, the user will be notified of what they need to fill in, and a link back to the form they just submitted will be provided.
|
| Syntax: | <input type=hidden name="required" value="name,email"> |
|
| Field: | env_report |
| Description: | This hidden field is used some further details about the user. Essentially this gets the IP address of the remote host, the remote address of the user and the HTP user agent employed. This is basically used to in case of attack and to gain more information about the local of the user.
|
| Syntax: | <input type=hidden name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT"> |
|
| Field: | sort |
| Description: | This field allows you to choose the order in which you wish for your variables to appear in the e-mail that FormMail generates. You can choose to have the field sorted alphabetically or specify a set order in which you want the fields to appear in your mail message. By leaving this field out, the order will simply default to the order in which the browsers sends the information to the script (which is usually the exact same order as they appeared in the form.) When sorting by a set order of fields, you should include the phrase "order:" as the first part of your value for the sort field, and then follow that with the field names you want to be listed in the e-mail message, separated by commas.
|
| Syntax: | <input type=hidden name="sort" value="order:name,email,message"> |
|
|
Download the Code:
Please use the following link to download the form-mail.pl zip package.
And the following link to download the complete site_example zip package.
More information on using the web templates from the
site_example zip package can be found on this
page.
|
If you enjoyed this page and would like to get more tips, tricks and offers to help you make the most of your most of your web presence please sign up for my Weekly e-mail newsletter. Please note that your details will never be sold and shared with others. You are signing-u for my e-mail only.
Click Here to Join
|