How to Set up FormMail

In this guide, you can learn how to set up the NMS FormMail script.

Set Up FormMail

Customize FormMail.pl Script

  1. Un-compress the downloaded file and upload the FormMail.pl script to your cgi-bin (you will only need to upload the FormMail.pl file, all other files are documentation).

  2. The next step is to modify the FormMail.pl that is inside your cgi-bin. There are only two lines that you will need to modify.

  3. The first is the @referers line. Replace everything inside of the parentheses with your domain, once without the www and then a single space and again with the www You will need to do this for each domain that you will be sending from. Remember, only one space between each url. The line should look like the example below:

    @referers = qw(example.com www.example.com);

  4. Now, modify the @allow_mail_to line. Here you specify any email addresses that the forms will send to. Again, only one space between multiple email addresses. Also, make sure you remove the ‘localhost’ entry. The line should look like the example below:

    @allow_mail_to = qw([email protected] [email protected]);

  5. Save the FormMail.

Configure Contact Form

  1. First, point the action of the form tag to the FormMail.pl script inside the cgi-bin.

    Pointing the the contact form to the FormMail.pl

    The following tag is necessary for your contact form to process the values in the form. Copy the code (below) and paste it into your Contact form’s code.

    <form action=”https://www.example.com/cgi-bin/FormMail.pl” method=”post”>

  2. Inside of your form you will also need to include a few hidden input tags. Copy the code (below) and paste it into your contact form’s code.

    Add the recipient(s) of the email:

    This tag will configure the form to send to the specified email address(es).

    <input type=”hidden” name=”recipient” value=”[email protected],[email protected]” />

    Create the subject of the email:

    This tag tells the form the subject to create the email with.

    <input type=”hidden” name=”subject” value=”From the contact form” />

    Redirecting the page to your own “Thank You” page

    This is another optional tag to specify where your users will be redirected to after they click the submit button. If you do not include this they will be directed to a very generic looking page created by the FormMail script.

    <input type=”hidden” name=”redirect” value=”https://www.example.com/thankyou.html” />

Change File Permissions

Change Permissions Using cPanel

  1. Log into cPanel.

  2. Click on the File Manager icon under the Files subheader.

  3. Browse to the cgi-bin by clicking on the folder icons for public_html > cgi-bin.

  4. Once inside of the cgi-bin directory, right-click on the FormMail.pl file and click to select Change Permissions.

  5. Click the checkboxes to ensure that the User column has read, write, and execute checked and Group and World should have read and execute checked.

  6. Click the Change Permissions button to save these changes.

Change Permissions Using FTP

If you are using an FTP client you will want to browse to the cgi-bin directory. Then right click on the FormMail.pl file and look for an option called CHMOD. This will open a dialog box where you can make the same changes as described in the cPanel file manager steps above. Make sure execute is turned on for all types of users and that the numbers have changed to 755.

Congratulations! Now you have a FormMail.pl script set up that you can use to send email from a contact form on your website.

48 thoughts on “How to Set up FormMail

    1. Hello TimH – According to cPanel, FormMail no longer works with cPanel. They state that it has been deprecated in this post from 2018: https://forums.cpanel.net/threads/formmail-no-longer-working-on-cpanel-70.629419/. I will review the article and update it as necessary. There is a clone of FormMail called NMS FormMail that is recommended for use (the link is at the beginning of the article). If you use that version and follow the recommended settings for SMTP, then it should work. If you continue to have problems, please provide us with details and let us know about the problem you’re having.

  1. The email program stopped working when I transfered my site to a new host.  I checked the permissions of FormMail.pl and it is 755, but I get this error message:

    If you are the webmaster of this site please log in to Cpanel and check the Error Logs. You will find the exact reason for this error there.

    Common reasons for this error are:

    • Incorrect file/directory permissions: Above 755.

      In order files to be processed by the webserver, their permissions have to be equal or below 755. You can update file permissions with a FTP client or through cPanel’s File Manager.

    • Incorrect Apache directives inside .htaccess file.

      Make sure you have not specified unsupported directives inside the local .htaccess file. Such include PHP settings and Apache module settings.

    help?? 

     

    Chris

     

    1. As a test, rename the .htaccess file to .htaccess.old and then retest the website. If it works then you know the issue resides in the configuration of the .htaccess file. If it does not fix the issue, rename the .htaccess by removing the .old you added to the end. That way, it won’t affect the website after you resolve the issue.

      Creating a phpinfo page will allow you to see the server environment, this can be used to compare to your old server setup.
      Thank you,
      John-Paul

  2. Changing permission in CPanel>File Manager

    public_html>cgi-bin>FormMail.pl

    to 755 on ‘FormMail.pl’ file

    worked for me.

    Thanks a lot!

     

     

  3. Looks like this only gives 500 error. Runs ok on command line producing kinda html code to screen, but no errors.

    perl version is 5.24.0

    kernel 4.10.10

    How to start looking where problem is?

  4. I have placed my .pl file in the cgi-bin folder, but I’m still getting, “The requested URL /cgi-bin/FormMail.pl was not found on this server.” Please help resolve this issue.

    1. David, make sure that your form HTML tag has ‘action=”https://example.com/cgi-bin/FormMail.pl”‘ as the listed action, where the value for ‘action’ is your domain. Alternatively, you may be able to use just “cgi-bin/FormMail.pl”, but this may depend on your hosting setup.

      Next, I would check to make sure that your permissions are set properly for your ‘cgi-bin’ folder, as well as your ‘FormMail.pl’ file.

      If neither of those resolves the issue and your web host is using cPanel, I would make sure that your ‘homedir’, and ‘scriptalias’ for the domain you are trying to set this up on are configured properly.

    1. You will need to contact your hosting provider to check and see why the server is not serving the Perl files properly.

  5. Thank you for the help with this script. I have some questions however..

     

    I have successfully received the email including the form information, but..

    The email I receive is from “nobody@blablabla” I attempted to add an email text box as mentioned above with no success. 

    The subject line does not show as I entered it.

    The thank you page does not redirect to my own page and uses the default. I have gone through and looked at your steps and my code but cannot seem to fix it.

     

    I appreciate your help!!

    1. Without seeing the actual code to compare, it is very difficult to say. Are you getting any error messages at any point? Be sure to go back through your code and ensure all the correct variables were changed to the settings you desire.

  6. I’d like to put an IF statement in somehow whereby the user sees “what’s 5 x 6?” and must enter 30 then I check that the answer is 30 or wont’ send the form. Getting a lot of spam. Can it be done?

    1. I’d suggest at using something like reCaptcha. Here’s a link that may help you out:

      https://www.google.com/recaptcha/intro/index.html

  7. Hi,

    I see there is a required function in the form but it isn’t yet clear (to me) how to engage this to assure specified required fields must be present. How do we dop that? (Thanks InMo team!)

    1. If you wish to force requirements for specific fields, you would need to code those handlers in the perl script. You can also add them in JavaScript to guide the visitor along. However, never just use JavaScript as it can be disabled from the client side and bypassed. Always check with your server side script (Perl, PHP, etc)

    1. Hello Barry,

      Thank you for contacting us. Yes, “Step 3” above explains how to input any email addresses that the forms will send to..

      If you have any further questions, feel free to post them below.

      Thank you,
      John-Paul

  8. Hi ,

    I’ve conffigured the FormMail.pl as per steps above and still it will not work, also done it correctly in the Form as well.

     

    What else can I do to make it work?

    1. Hello Kisubiboy,

      Sorry for the problem with the Form. However, in order to help you we would need more information. If you are hosted with us, please provide us some account information so that we can look at where you have implemented the form. Do you get any error messages? Can you provide us a copy of the code you saved? We can’t determine why the form is not working without a little more info.

      Kindest regards,
      Arnel C.

  9. Is there a way to import a list into the mailform? I am currently using Mailchimp to send out a daily HTML of our site to out 560+ subscribers and I would liek to import them into the site

     

    1. Hello Stephen,

      Not by default as this is a simple script setup. You could of course code your own import where it stored the list in a database and sent out mails using that list. That is not part of this article, however.

      Kindest Regards,
      Scott M

    1. Hello David,

      Probably the easiest way to add the attachment would be to simply go to the HTML portion of the email form and add a link to the attachment that you wish to add.

      I hope that helps to answer your question! If you require further assistance, please let us know!

      Regards,
      Arnel C.

  10. I did everything as u mentioned but its giving 502 gateway error… Please Help me with this…

     

     

    Regards,

    Gourav

    1. Hello Gourav Batra,
      Sorry to hear that you’re having problems with the 502 gateway error. There are MANY things that a 502 bad gateway error could be. We need more specific info on the account and how you’re getting the error, please. If you can provide more information, then we can look further into the problem that you are having.

      Kindest regards,
      Arnel C.

  11. sorry I dont see the post but I see a duplicate of the first post. I will try again.

    <form action=”https://www.trainingindustrialmachinesandequipment.com/cgi-bin/FormMail.cgi” method=”post” >
     <input type=”hidden” name=”recipient” value=”[email protected],[email protected]” />
     <input type=”hidden” name=”subject” value=”From the feedback form” />
     <input type=”hidden” name=”redirect” value=”https://www.trainingindustrialmachinesandequipment.com/confirmation.html” />
     <input type=”hidden” name=”reset” value=”reset”/>
     Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       <input type=”text” name=”name” style=”width: 385px”/><br />
       <br/>
     Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
       <input type=”text” name=”email” style=”width: 379px”/><br />
       <br/>
     Comments:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class=”auto-style4″>
       <textarea name=”comments” class=”auto-style5″ style=”width: 408px; height: 166px” rows=”1″></textarea></span><br />
       <br />

      <INPUT TYPE=”submit” value=”Send e-mail”/> <INPUT TYPE=”reset” value=”reset”/>
    </FORM> 

    1. Hello Ed,

      We do appreciate the comments and questions. In the future, if there’s anyway that you can consolidate the code to as few posts as possible, then we can reply to them much quicker.

      I went through your code with Jeff, and it all appears normal to us. The form looks okay as well. On our servers this script is meant to run as a Perl script, so that might be the issue. You may need to talk with your host to see why the script is running completely. Or at least why the email portion is failing to send you a message. They may need to check the logs to see if they can find any error or indication of the mail being processed at the server.

      Apologies that we can’t give a direct answer. Hopefully, this does lead you to a solution. Please let us know if you have any further questions or comments.

      Regards,
      Arnel C.

  12. I should have told you after nothing was working but the confirmation page. I changed the FormMail.pl to FormMail.cgi. Nothing changed, but that is why you will see the cgi at the end of FormMail in my action script.

    Thanks Ed

  13. Below is my form code

    Name:                      

    Email:                       

    Comments:         

    Thanks Ed

    I get a confirmation page but do not get email?

    $DEBUGGING         = 1;
      $emulate_matts_code= 0;
      $secure            = 1;
      $allow_empty_ref   = 1;
      $max_recipients    = 5;
      $mailprog          = ‘/usr/lib/sendmail -oi -t’;
      $postmaster        = ”;
      @referers          = qw([email protected] www.trainingindustrialmachinesandequipment.com);
      @allow_mail_to     = qw([email protected] www.trainingindustrialmachinesandequipment.com);
      @recipients        = ();
      %recipient_alias   = ();
      @valid_ENV         = qw(REMOTE_HOST REMOTE_ADDR REMOTE_USER HTTP_USER_AGENT);
      $locale            = ”;
      $charset           = ‘iso-8859-1’;
      $date_fmt          = ‘%A, %B %d, %Y at %H:%M:%S’;
      $style             = ‘/css/nms.css’;
      $no_content        = 0;
      $double_spacing    = 1;
      $wrap_text         = 0;
      $wrap_style        = 1;
      $address_style     = 0;
      $send_confirmation_mail = 0;

    I have this FormMail.pl in my cgibin folder.

    What am Idoing wrong?

    Any help is great.

    Ed

  14. I get a confirmation page but do not get email?

    $DEBUGGING         = 1;
      $emulate_matts_code= 0;
      $secure            = 1;
      $allow_empty_ref   = 1;
      $max_recipients    = 5;
      $mailprog          = ‘/usr/lib/sendmail -oi -t’;
      $postmaster        = ”;
      @referers          = qw([email protected] www.trainingindustrialmachinesandequipment.com);
      @allow_mail_to     = qw([email protected] www.trainingindustrialmachinesandequipment.com);
      @recipients        = ();
      %recipient_alias   = ();
      @valid_ENV         = qw(REMOTE_HOST REMOTE_ADDR REMOTE_USER HTTP_USER_AGENT);
      $locale            = ”;
      $charset           = ‘iso-8859-1’;
      $date_fmt          = ‘%A, %B %d, %Y at %H:%M:%S’;
      $style             = ‘/css/nms.css’;
      $no_content        = 0;
      $double_spacing    = 1;
      $wrap_text         = 0;
      $wrap_style        = 1;
      $address_style     = 0;
      $send_confirmation_mail = 0;

    I have this FormMail.pl in my cgibin folder.

    What am Idoing wrong?

    Any help is great.

    Ed

Was this article helpful? Join the conversation!

Questions about our MailChannels Deployment? We have answers and are here to help!Learn More
+