Support»Tutorials»FormMail Tutorial and Installation How To

This tutorial describes how to use FormMail, the most common form mailer, with your Nexcess web hosting account.

A form mailer is an easy way to take a web form (i.e. contact page, information request etc.) and have the submitted results e-mailed to a given e-mail address. Many websites use this type of system to deliver any contact request to the correct department via e-mail from a web form.

If you've already run through the FormMail tutorial and uploaded the FormMail.pl file then you can skip down to the Form creation section.

Follow these steps to complete the tutorial:

  1. Download (right click on the link and select 'save as') the FormMail CGI script and save it to your local machine (your Desktop is most likely the easiest place to save it for now).
  2. Open the FormMail.pl file you just saved in notepad, simpletext or any other text editor.
  3. You need to change 2 lines in the FormMail.pl file to make it work with any form you'd like to send. The first thing to change is the 'referrers' line which specifies which sites are allowed to submit forms for mailing. You should only allow your site and Nexcess. If you allow other sites this may open up your FormMail installation for spammers so it's very important to just put your domain name and Nexcess. Just change:

    @referrers = qw(dave.org.uk 209.207.222.64 localhost);

    Referrer settings

    In place of the 'dave.org.uk 209.207.222.64 localhost' just put your domain name and Nexcess (so your temp domain will work as well), for example:

    @referrers = qw(johnsmith.com nexcess.net);

    Domain settings

  4. The next thing to change is the 'allow_email_to' line which specifies which e-mail addresses are allowed to be used as recipient addresses in forms. Again, you should only allow your site and Nexcess which will allow e-mail to be sent from your form to any e-mail address belonging to your domain.

    @allow_mail_to = qw(you@your.domain some.one.else@your.domain localhost);

    Allow e-mail settings

    In place of the 'you@your.domain some.one.else@your.domain localhost' just put your domain name and Nexcess, for example:

    @allow_mail_to = qw(johnsmith.com nexcess.net);

    Domain settings

  5. Once you've made these changes you need to FTP the FormMail.pl file to your cgi-bin directory on your web hosting account. The cgi-bin directory is located in your html directory and is created as a standard part of your Nexcess web hosting account.

    If you are unsure about how to FTP your file to your site space just follow one of our FTP tutorials. Make sure you upload the file in ASCII mode which should be the default.

    IMPORTANT: Once you upload the FormMail.pl file into your cgi-bin make sure you change the permissions of the file to '700' which can be done through your FTP program. This is usualy referred to as 'chown' in your FTP program and is explained on our FTP tutorial pages.

  6. The next step is to create the actual HTML form which is where you will setup what types of data you want to collect from your users.

    Creating HTML forms for use with FormMail is very easy. For example, if you'd like to create a form where users can submit a comment or question your html page would look like this:

    <html>
      <body>
        <form method="post" action="/cgi-bin/FormMail.pl">

          <!-- The next 2 'hidden' fields are used to configure FormMail -->
          <input type="hidden" name="recipient" value="john@johnsmith.com">
          <input type="hidden" name="subject" value="Web Form Submission">

          First Name:<input name="First_Name" type="text"><br>
          Last Name:<input name="Last_Name" type="text"><br>
          E-mail:<input name="e-mail" type="text"><br>
          Comments:<br>
          <textarea name="Comments"></textarea><br>
          <input type="submit" value="Submit Form">
        </form>
      </body>
    </html>

    If you used the previous block of HTML code your resulting page will look something like this:

    Submit form

    The 2 lines:

      <input type="hidden" name="recipient" value="john@johnsmith.com">
      <input type="hidden" name="subject" value="Web Form Submission">

    are used by FormMail internally and can be used to configure how and where e-mails are ultimately sent. The first line with the 'name="recipient"' field is used to tell FormMail where it should send the e-mail. Just change the 'value="john@johnsmith.com"' portion to use your e-mail address and the e-mail generated by FormMail will be sent to you.

    The second line is used to change the 'Subject' line in the e-mail you receive. Again, just change the 'value="Web Form Submission"' to a subject of your choice and that's all you need to do to alter the subject.

  7. At this point (once you uploaded the FormMail.pl file and made the HTML page) you are ready to test out your form. Just enter in some test information on your form and press the 'Submit' button. If it works, you'll receive and "Thank You" page and if it doesn't you'll receive an error page.

    The most common error page is the one shown below. It usually means that the e-mail you put in the 'recipient' section laid out in step 5 isn't the same domain as you allowed in your @allow_email_to line laid out in step 3. Double check these values along with your @referrers value to make sure they are all consistent and try again.

    Error page

  8. That's the basics of using FormMail. There are many more options you can use (such as redirecting to a self-made page upon form submission) that are out of the scope of this tutorial. You can read about these and other options at the FormMail main page.

    If you'd like us to elaborate on any of the other options in this FormMail tutorial just contact us. The FormMail tutorial is now complete.