How do I install and configure FormMail?

FormMail setup and configuration.

One FormMail installation on your site can be used by multiple contact forms from multiple sites to email a form’s contents.  The script can be configured to only send emails to particular addresses or domains as well as to only be used by particular domains or IPs.  This allows you to restrict your forms from sending to people that should not get the emails as well as to prevent other websites from using your FormMail script.

1 – We recommend the Formmail script from Matt’s Script Archive at  You can download a zip folder with the script and readme file here.

2 – After downloading the Perl script file, you will need to configure it using a text editor made for webpage editing (Notepad will work, but other text editors available online will make things easier with more features and colors).

3 – In your text editor, you will need to define the variables at the beginning of the code.  Everything after the code in the box of number signs should not be touched.

There are two variable arrays that need to be configured; @referers and @recipients.  The image in this link show some examples of the types of values you might put into the two arrays:

Example configuring


This array contains the domains and addresses that are allowed to call this script from their forms.  Any page at a domain listed here can use this script in their forms.  You would ONLY want to list the domain name or IP address of pages that you want using this script!  (For example, the form on YOUR website).  Try to keep this as restricted as possible so other sites don’t try to link to your form.

The following example shows what this line might look like. Each value in the array is a domain that would have a form that will use this script:

@referers = ('','','','');


This array allows you to specify exactly who can be sent an email from the form.  If only one email is listed, then only they can receive the message.  If multiple emails are listed, and your form is setup to allow the users to select the address they wish to send the email to, then only email addresses listed here will be able to get the message in the case that the user enters more than those ones.  Again, you want to keep this restricted to ONLY the email addresses that you want to receive the user written emails from the webpage.  The default setting is:

@recipients = &fill_recipients(@referers);

which is basically anything@(domains/addresses listed in @referers), for example ‘’ if is listed in @referers.
By default, FormMail allows letters, numbers, underscores, hyphens, and periods in the email address.  You can add or remove allowed characters by viewing additional documentation at Matt’s Script Archive, however they suggest using the default to prevent allowing unnecessary characters.

&fill_recipients = [A-Za-z0-9_-\.]+

where the backslash(\) is an escape to allow a period. We do not recommend making any adjustments to ‘&fill_recipients’ unless you are looking for some sort of advanced special setup.

Below is an example of what you would put in the array @recipients.  the ‘^’ represents the start of the string and the ‘\’ are escape characters to allow the periods and @’s.

@recipients = (&fill_recipients('','',''),'^johnny\@differentdomain\.com', '^user2\@their\.domain\.com', (&fill_recipients(@referers), '^bob\@[100\.100\.250\.250]'   );

So if you just want one email to receive the messages from the form, put:

@recipients = '^first\.last\@domain\.com';

That would be the safest way to protect against spammers.  Just list the exact emails you want receiving the messages from the user input.

4 – Save the file then upload the file to the ‘/public_html/cgi-bin/’ folder on the Zenutech server by FTP.

5 – set the file permissions (chmod) for to 755 on the server side.

6 – The script is now ready to be used by any form on your website, provided you configured it to do so.  Now you want to make sure the forms that will be using the script contain the inputs that the script looks for. On each form, there is only one default input required, that is name=”recipient”:

<input type="hidden" name="recipient" value=",">

This determines who the email will be sent to.  The user can enter multiple email addresses separated by commas and only the ones allowed by the script configuration done earlier will go through.  Most often you would likely want this input field hidden to the user and just have the desired email address(es) listed as the value as shown above.

Some other input fields the script will look for are :

name=”subject”    which will be the subject line of the email
name=”email”   which is the return email address of the sender
name=”realname”    which is the name of the sender
name=”redirect”   which will take the user to a desired URL after they submit the form information (rather than going to the script’s default ‘thank you’ page)
name=”return_link_url” which will be the web address the user can return to from the default results page. If you use the “redirect” input, then this value will not be used.
name=”required” which will specify to the mailing script that the input names listed as its value are required fields that the user needs to enter.
name=”sort” which arranges your custom inputs in the order you specify to form the email message body.

Below is a sample template form you can include inside your HTML body (Please note you would want to put an actual email address for the value of ‘recipient’ and an actual URL for the value of ‘redirect’):

<form name="input" action="/cgi-bin/" method="post">
<!--recipient field - who the user wants the form contents to be emailed to(use comma to separate values)
generally best to be kept hidden and set to a value-->
<input type="hidden" name="recipient" value=""/>

<!--If you wish to choose what the subject is:
<input type=hidden name="subject" value="Your Subject"/>

<!--To allow the user to choose a subject (you can make as a "hidden" element if you want a static subject)-->
<input type="text" name="subject"/>

<!--return email address of user-->
<p>return email address</p><br/>
<input type="text" name="email"/>

<!--real name of user-->
<p>Your Name</p><br/>
<input type="text" name="realname"/>

<!--write message-->
<p>write your email here</><br/>
<input type="text" name="message1" size="100"/>

<!--write message-->
<p>this will get shown below previous message</><br/>
<input type="text" name="message2" size="100"/>

<!--arrange message body-->
<input type="hidden" name="sort" value="order:message1,message2"/>

<!--tell the script which inputs the user must fill out in order to send the email-->
<input type="hidden" name="required" value="realname,email,message1"/>

<!--after form is submitted, the user will go to this address-->
<input type="hidden" name="redirect" value=""/>

<!--the submit button-->
<input type="submit" value="Submit" />

7 – For more information and advanced settings, the readme file is available at Matt’s Script Archive

Posted 2010-07-06 in Site Management,Web Development