Uniform Mail : Form Mail Script

Introduction to Form Mail

Feedback from users is important to most commercial websites (and some hobby/information sites). The simplest way to allow feedback is to publish an email address and, possibly create a link with an url that reads something like mailto:wilma. flintstone@bedrock.net. When a user clicks the link, their default email client (e.g. Outlook Express) will open.

For many sites, this is sufficient. However, email spammers collect email addresses from websites using automated programs so publishing an email address this way is to be avoided. (It is possible to use javascript to avoid the spam problem but this falls outside the scope of this discussion.)

The next method of providing feedback is to create a form that the user fills in and sends to you. This has the advantage that you can request specific data. You create the form with the following HTML code

<form action="mailto:fred.flintstone@bedrock.net?subject=Dino"
      enctype="text/plain"
      method="post">
   ...... form contents
</form>

When you click the SUBMIT button on the form, the user's email client is opened and the data is sent. You can make this more sophististicated by using javascript to validate the form's contents before calling it's submit method. You may also use javascript to hide the email address (from spambots).

However, this still needs the user's email client to send the data (a bit clunky) and you may not wish users to know the address to which that data is sent. In addition, you might want the data to be sent to several departments and this would require automated forwarding at your end. 

Form Mail Programs

The solution to the problems outlined above is to use a form-mail program. Such programs run on the server (not on the user's computer). The form data is sent to this program and the server then sends it to the required address(es).

There are several tasks in creating a form mail system.

  1. Create the HTML page (including the form) in which the user enters required data.
  2. Validate the data and return the user back to the page highlighting errors (if any).
  3. Send the form data.
  4. Issue a confirmation so that the user knows the mail was sent correctly.

Some form mail programs perform all these tasks, however, the main Uniform Mail program (uniformmail.pl) only normally performs parts 3 and 4. Version 2.x can perform validation and provide a backlink to return to the form, however, the javascript program uniformmail.js is better suited to this task since it can highlight invalid data fields.

Uniform Mail : Main Features

What Uniform Mail cannot do

Uniform Mail : Installation

Having downloaded the Uniform Mail package, the first task is to install the main program, uniformmail.pl on your server.

uniformmail.pl is a perl script. Normally you should place it in a subdirectory of /cgi-bin. e.g. create a directory called formmail in the /cgi-bin directory and upload uniformmail.pl into this directory. When uploading, you must use ASCII mode otherwise the end-of-line markers may be invalid and the script will fail.

Internet Explorer and FTP

If you use the built-in FTP capabilities of Internet Explorer to upload your files, you've got a problem - it does not seem to support ASCII mode so you will have to use the command-line program ftp.exe. You will need to use the commands open (to connect), ascii (enter ascii mode), cd (change directory), dir (get directory list) send (upload the program) and quit.

Access Rights

You must set the access rights of the script file and the directory to 755. If you have command-line access to the server, this is typically done using the chmod command. If you are using Internet Explorer, right click the directory and choose properties from its popup menu. An array of boxes will be displayed representing 9 attributes. The Owner must have complete access (all three boxes ticked). Other groups should be given execute and read access. Repeat this process for the script file uniformmail.pl

Testing the installation

To verify that it has been installed correctly, open a browser window and type in an url of the form :-
http://www.yourdomain.com/cgi-bin/formmail/uniformmail.pl

If it is working correctly, an error page should be displayed that reads something like MAIL ERROR: File not found - uniformmail.params. (Don't worry if a slightly different error message is displayed, it just means the script has been modified slightly since this was written.)

If it fails, do the following.


 

Authentication

Smtp servers may require authentication, unfortunately, this is not supported by Uniform Mail. However, authentication is not normally required if :-

  • The connection to the mail server is local.
    i.e. you are using an smtp server on the same domain as the mail program.
      OR
  • Mail is sent only to local mailboxes e.g. you@same-domain-as-smtpserver.com

Since both these criteria will be met normally, you should not experience problems. If both these criteria are met (or you cannot meet one of them) and you are experiencing problems :-

  • Contact your network administrator, explain the problem clearly and concisely - they may be prepared to change the server configuration.
      OR
  • Using a text editor such as notepad open uniformmail.pl and search for authentication.
    You may embed a username and password in the program code. HOWEVER, whether this works is dependent on what authentication protocols are supported by the mail server and by your distribution of perl. THIS CODE IS UNTESTED.
    Also, placing a username and password in a text file, even one that cannot be read by the public, should not be done without due consideration of the security implications.