Creating a Contact Form with FormMail

FormMail is a very popular script that you can put onto your website so that visitors can fill it out and have their response emailed directly to you. To help you set up FormMail on your website we have written a step-by-step guide to installing and configuring FormMail: If you missed our previous article, please see the How Contact Forms Work tutorial.

  1. Download the “compat” version of the NMS FormMail script.
  2. Un-zip the downloaded file and upload the script to your cgi-bin folder in your public_html folder.
  3. Next you will need to modify the file that was uploaded into your cgi-bin folder. First, you will need to change the @referers line (around line 47). Replace everything inside of the parentheses with your domain using the same formatting, once without the www and then a single space and again with the www.
  4. This is where you input any email addresses that the forms will send to. Make sure you remove localhost from both the @referers and the @allow_mail_to lines (around lines 47 and 48, respectively.) Once you have made these two changes, save the file.
  5. After adding the code to the page that you want the form on, you will need to point the action of the FORM tag to the script inside the cgi-bin folder:
     <form action="" method="post">
  6. Next, inside of each of your forms you will need to include a few hidden input tags. They are detailed below:
 <input type="hidden" name="recipient" value="[email protected],[email protected]" />

This tag tells the form which email address to send the form to. Just make sure that this email is one of the addresses in your @allow_mail_to field

 <input type="hidden" name="subject" value="From the feedback form" />

This is a optional tag you can input into your form to specify the subject line of the email that gets delivered to you.

 <input type="hidden" name="redirect" value="https://www.your.domain/foo.html" />

This is another optional tag to specify where your users will be redirected to after they click the submit button.

Finally in order for FormMail to work you must set the permissions on the to 755.  This can be completed within your File Manager as well by right clicking on the file and selecting “change permissions.” For more information on this course please visit Adding Contact Forms.

Updates for Shared Servers

If you are creating a form on a shared server (business class account), then all form feedback will automatically be set to come from “nobody”. This was done in order to be able to add an email origin for emails coming from scripts on shared servers. The main purpose for this setting was to help stop spam. Previously, messages generated from scripts were difficult to track. Setting the form to use the email systems on the server helps to reduce load on the server.

You can set the form to use SMTP by looking for the following line in the script:

$mailprog = ‘/usr/lib/sendmail -oi -t’;

Then, you would replace it with:

$mailprog = ‘’;

If you require help finding your email server settings, please see “How to Find Email Settings.”

69 thoughts on “Creating a Contact Form with FormMail

  1. Can you please confirm that “Updates for Shared Servers” listed at the bottom of the article will allow to work with the current shared server limitations?

    1. Hello TimH – According to the article on How to Set Up Formmail – the clone version NMS FormMail – should work. Make sure you’re using this script and the options that are listed in the article. If you’re using NMS FormMail and you’re still having problems, then please provide us with details on the issue and we can investigate it further.

  2. Does anybody know if FormMail is actually function on InMotion?

    The Support Chat said that the sendmail was disabled due to spam. Yet it was working for feedback forms which sent an email to a home domain email address ( where @recipients is the same as @allow_mail_to ) from [email protected]

    Now there is a Error 500 – Internal Server Error.

    Does anybody know what’s going on?

    1. Hey Max, I’m sorry to hear that you’re running in to trouble. Based on the 500 error, the most likely explanation to me is that there is either a database issue, or possibly an IP address block due an overactive security system. Please get in touch with our live 24/7 Technical Support team. They’ll be able to review your account and error logs and see exactly what is happening on the server side to help you resolve the issue.

  3. Hello,
    I work on a contactform and everything works almost fine. When I confirm the form so the data will be send as a confirmation email. But the problem is that there are some fields I won’t see in the email.
    At least the “utf-8” encryption or the “confirm” when I confirmed the form. So can I hide this fields somehow so I wouldn’t see it in the email I get?

    fehler = error
    Nachricht = Message

    That’s my code:



    1. You should be able to remove the unwanted fields by erasing the section from the table. The EXAMPLES file includes additional examples you can compare with.

  4. I was using PHPMailer but it stopped sending emaills to yahoo addresses due to Yahoo’s increased security measures. So I tried
    FormMail.pll will not send to Yahoo addresses either. Is there something I need to change to allow the form to send to Yahoo.??

    $DEBUGGING = 1;
    $emulate_matts_code= 0;
    $secure = 1;
    $allow_empty_ref = 0;
    $max_recipients = 5;
    $mailprog = ‘’;
    $postmaster = ‘[email protected]’;
    @referers = qw(;
    @allow_mail_to = ();
    @recipients = ();
    %recipient_alias = (‘recvr’ => ‘[email protected]’,’[email protected]’,);
    $locale = ”;
    $charset = ‘iso-8859-1’;
    $date_fmt = ‘%A, %B %d, %Y at %H:%M:%S’;
    $style = ”;
    $no_content = 0;
    $double_spacing = 1;
    $wrap_text = 0;
    $wrap_style = 1;
    $address_style = 0;
    $send_confirmation_mail = 0;
    $confirmation_text = <<'END_OF_CONFIRMATION';
    From: [email protected]
    Subject: form submission

    Thank you for your form submission.


    Test Contact



    Please enter your comments

  5. I am getting frustrated, Ugh

    <form action="" method="post">
    <input name="recipient" value="------------------------" type="hidden">
    <input name="subject" value="Application Submittal" type="hidden">
    <input name="redirect" value="https://-------------------------" type="hidden">

    I edited the as per the instructions above to the best of my understanding.

    I don't get any email and redirected to unrelated sites

    1. Apologies that you’re getting frustrated with Form mail script. The code that you’re providing is typically what’s in the HTML form that is seen from the website. We would need to see what you entered in the script to determine if there are no problems there. You can reply and place that information here. Nothing that you post here is shown to the public until approved. We would remove that information before publishing. Or, you can also submit a ticket to our live technical support team per the email address at the bottom of this page. They can then handle issue privately. All posts on the Support Center are typically public, though we do remove all confidential customer information before publishing. Please provide us more information and we can look into the issue in more depth.

  6. Hello–

    I switched to InMotion Hosting this year and I am having some issues with running some custom MailTo perl scripts where they worked fine with my previous web host. I have managed to adjust the code somewhat, but now am faced with none of the named fields passing the values to the perl script.

    So I went ahead and setup according to the accompanying instructions. I setup a test using “Example 1:  A simple feedback form” as per the EXAMPLES file.

    I configured the specific settings for my domain in both and my test HTML page to call the script.

    The results are missing the “name=” values in both the response page and the sent email. This seems to match the issue observed with my custom perl script mentioned earlier as if the “name=” fields are not getting passed along to the perl script as expected.

    With the Example 1 test, the perl script does not even see the ‘method=”post”‘ reference, so it responds with the appropriate error message with an example showing the ‘method=”post”‘ example.

    I set the $secure value to ‘0’ so it would ignore the “missing” method issue. And that is when the submt completes, but without showing any of the “name” field values in the response or sent email.

    Here is the form portion from the test HTML page:

    <form method="post" action="">
        <td>What is your name ?</td>
        <td><input type="text" name="name" /></td>
        <td>What is your favorite animal ?</td>
        <td><input type="text" name="animal" /></td>
        <td colspan="2"><input type="submit" /></td>

    Any assistence with appreciated.



    1. I recommend you contact FormMail Support any possible server settings that may need to be adjusted. You can also right-click the webpage and select console or Debugger to view any errors. Once you get more info, please contact our live support for further assistance.

  7. I have installed the  On the client side everything seems to work fine.  However when I recieve email from the form/ it’s blank.  No other errors.  How can I correct this?

    1. Have you run any other tests on the email? Have you checked the variables? Are any not filling properly? If so, which ones?

  8. I just placed a form on our site but apparently, the form is not seeing the cgi-bin.  I am receiving a 404 error message when I run the form

    1. Thanks Dave!

      The typos have been corrected!

      If you have any further questions or comments, please let us know.

      Arnel C.


    I’m trying to complete step 7 above.

    I’m not sure what changing the permissions does, or if it will affect anything else on the website. I’m just trying to follow the instructions above, and hoping for the best.


    1. The permissions regulate who can access the file and who cannot. Having the permissions set right can be crucial to the function of the script. They need to be set ‘not too strict’ and ‘not too loose’ for proper security.

  10. My problem is that I got the form set up and it submits but the data is empty where it should have the items that I submitted. Is something wrong with my code? my code is here:


    <form action=”” method=”post”>

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

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

        <div class=”row”>

          <div class=”large-6 columns”>


              <input type=”text” placeholder=”Full Name” />



          <div class=”large-6 columns”>


              <input type=”text” placeholder=”Email” />




        <div class=”row”>

          <div class=”large-4 columns”>

            <label>Phone Number:

              <input type=”text” placeholder=”Phone Number” />



          <div class=”large-8 columns”>

            <label>What are you interested in(check all that apply)


          <input id=”checkbox1″ type=”checkbox”><label for=”checkbox1″>Printing


          <input id=”checkbox2″ type=”checkbox”><label for=”checkbox2″>Web Development


          <input id=”checkbox2″ type=”checkbox”><label for=”checkbox2″>Promotional





        <div class=”row”>

          <div class=”large-12 columns”>


              <textarea placeholder=”small-12.columns”></textarea>




        <br><button class=”button” name=”Send” type=”submit”>SEND</button><br>


    1. Hello Ryan,

      I got your form to work fine, but to do so you will need to add a “name=’name'” to each field. For instance, the full name field, you will want to add “name=’fullname'” or something like that so that the formmail picks it up as data. Do this for every field and you will see the email come through with the data.

      Kindest Regards,
      Scott M

  11. Thanks for fixing it. I put “Refugee Relief” back where you had it and it works perfectly now.  I will change the @allow_mail_to  back to the real email instead of the test email that goes to me, so if you are going to do anything else to the form please let me know first so I can change it back to test. I don’t see anything else that needs to be done though, it works fine now.

    I hope that the instructions on inmotion hosting’s website on creating a formmail will be updated to include the changes we’ve made and will state approximately what line these changes are on so when I or someone else need to make a new form on another website it will be straightforward.

    I have one more question. I got a spam email that used the form.  When I signed up for hosting I did not include that extra charge for what I think was McAfee on the email account.  Would adding that help us not get spam sent through the form?


    1. Hello Liz,

      We are happy it is now working for you. Arnel and I had fun crawling through the code and testing different things. (Well, I had fun. I’m not sure about Arnel.) We will change the article to tell how to make the changes, but we hope to be able to modify the code where it is done more easily and not have to crawl through all the code, even if we give the approximate line number. We didn’t write the original so we have to make sure any changes we make do not break anything else.

      As for the McAfee, adding that will have no effect on the form. Forms with no human verification method such as Captcha (and even then, no guarantee) are often hit by spam bots and automatically filled out. We even get them daily in our questions and comments. It is a constant cat and mouse game and although we can put enough checks in place to practically eliminate all bots, it makes things more difficult for the customers like yourself. So we deal with them as they come for the most part.

      Adding a captcha to the form would not be a bad idea, but we do not have any code for that in place for the formmail. Keep checking back as we do want to create a tool for customers that creates a very nice custom form with optional human verification in it.

      Kindest Regards,
      Scott M

  12. I changed  return $email; on line 2720  to  return Refugee Relief Form; and got an error message as shown below.  I’ve changed it back for now so the form will work while I’m working on it.  I  didn’t get any “IAMTHEFORM” emails.

    By the way, since I changed $mailprog = ‘/usr/lib/sendmail -oi -t’; 


    $mailprog = ‘’;

    the form hangs so long before sending that people might think it is broken.


    Error 500 – Internal Server Error

    An error was encountered while processing your request. Typically this is a temporary condition. Please contact the web site owner for further assistance.

  13. I sent in a previous message that the form now gives me an error message as seen below. I put that last line back the way it was but still getting the error message. Did you change something else on your end?  I have to get the form working at least to where it was before.


    Error: Bad or Missing Recipient

    There was no recipient or an invalid recipient specified in the data sent to FormMail. Please make sure you have filled in the recipient form field with an e-mail address that has been configured in @recipients or @allow_mail_to. More information on filling in recipient/allow_mail_to form fields and variables can be found in the README file.

    The recipient was: [ [email protected] ]

    1. Liz,

      Sorry about this craziness. I looked at the script and the only thing I had left in place was my test email address in one of the fields. Apparently, leaving that email address in the field caused the form to choke. As soon as I removed it, I could see it working instead of giving you the error. I diagnosed it by looking at what the form was sending as a recipient ([email protected]) and what the script was expecting. It should be okay now. You can try making that change to the text as per the above. I’ll make sure to double-check this tomorrow when I get into the office to make sure everything’s okay. Have a good evening!

      Arnel C.

  14. Unfortunately now I get an error message.  I’m going to put it back the way it was so the form will work until we fix it.

    Error: Bad or Missing Recipient

    There was no recipient or an invalid recipient specified in the data sent to FormMail. Please make sure you have filled in the recipient form field with an e-mail address that has been configured in @recipients or @allow_mail_to. More information on filling in recipient/allow_mail_to form fields and variables can be found in the README file.

    The recipient was: [ [email protected] ]

    FormMail © 2001-2003 London Perl Mongers

  15. I understand.  Thank you for all your help and I look forward to getting the fix for that part of the form when you get one.  The form is much better now and not as likely to end up in junk mail.

    1. Hello Liz,

      I’ll add this reply here for anyone reading through this issue in the future (and I’ll send you an email as promised).

      I found the “submitted by” text within the script. It’s on line 2841. I replaced the code with text. You can open the file and take a look. Currently, any form will read, “submitted by the webmaster of”.

      Check it out and let us know if you have any further problems!

      Arnel C.

  16. Fabulous!  It now says from “Refugee Relief Volunteer Form”  in the from part of the email. Below that though it still says “…submitted by ()…”  Is there a way to change that?  Also for the lag time if there is no way to fix that I’ll put a note on the page that the form might take a little while to send.

    1. Hi Liz,

      Believe it or not, we’ve actually been looking at that particular part of the form – we’re still looking for a way to change to that. This form wasn’t made by us, unfortunately. As soon as I find a solution for it, I’ll email you directly. As for the lag, it has to do with the mail being delivered on the server, so it may take a few minutes depending on the server load. We do appreciate your patience on the issue.

      Arnel C.

    1. Liz,

      Sorry you’re getting the error. I was working directly with your form and I never got any of those errors. The code is very specific. Make sure that you’re putting single quotes around the value you change and then end it with a semi-colon. If you don’t do that, you will get the 500 error.

      I changed the value to “The Form” for now. Check it out and see if it’s working. If you’re still seeing it fail, please let me know immediately.

      Arnel C.

    2. Hi Liz,

      No problem – I made sure that my example code in the comments above was technically correct using single quotes and a semicolon. I also changed in the form so that you could see it. You simply have to change the text in between the single quotes.

      Kindest regards,
      Arnel C.

  17. Ok, I put in the corrected code, uploaded it twice.  I get the same “from nobody” results and the same “submitted by () as before.  I even checked it in 2 different browsers that didn’t have the form in its cache.

    1. Hello Liz,

      I’m probably going to spending some time updating our documentation because of your request, but that’s a good thing. Sorry for the delay in getting this fixed the way you wanted. Here’s what needs to be changed.

      In your FORMMAIL.PL file, open the file to edit it and then look for the following line:

      return $email;

      If you’re using the code editor, it should be line 2720 (or around there).

      We changed this in your actual form online and it works. I changed it to “IAMTHEFORM” and tested it – you should see the test emails (pardon my silliness in the form). When you change it, make the line look like this:

      return ‘IAMTHEFORM’;

      Please try this out and replace the ‘$email’ with your FROM value that you wish to use. Apologies again for the delay in getting this straight. Let us know if you continue to have any problems.

      Arnel C.

  18. I commented out line 45 that said

    $mailprog          = ‘/usr/lib/sendmail -oi -t’;

    and replaced it with 

    p class=”code_block”>$mailprog = ‘’;

    and got an error message

    Error 500 – Internal Server Error

    An error was encountered while processing your request. Typically this is a temporary condition. Please contact the web site owner for further assistance.

    1. You may have seen my comment before the formatting was edited just a few seconds after it was posted. Please see the comment as it currently is as it contains the correct code without the formatting error.

  19. I didn’t find anything on 1777 but on 1780 I found the following

    An SMTP relay can be specified instead of a sendmail compatible mail program,
    using the prefix C<SMTP:>, for example:
    ‘mailprog’ => ‘SMTP:mailhost.your.domain’,
    Default: C<‘/usr/lib/sendmail -oi -t’>

    and I changed the ‘mailprog’ => ‘SMTP:mailhost.your.domain’, to 

    ‘mailprog’ => ‘’,  but I think I was just changing an example and not the code since there was no $ in front of it.  It didn’t do anything.

    1. I apologize, I made an error in my comment. Simply replace:

      $mailprog = ‘/usr/lib/sendmail -oi -t’;


      $mailprog = ‘’;

  20. I could not find a line that says $mailprog = ‘SMTP:mailhost.your.domain’;

    In searching for anything with $mailprog all I found is what I’ve pasted below.  Theses are in different sections of the file.

    The only references I could find to  are below.  I can email you the whole formmail if you want.


    use vars qw(

      $DEBUGGING $emulate_matts_code $secure %more_config

      $allow_empty_ref $max_recipients $mailprog @referers

      @allow_mail_to @recipients %recipient_alias

      @valid_ENV $date_fmt $style $send_confirmation_mail

      $confirmation_text $locale $charset $no_content

      $double_spacing $wrap_text $wrap_style $postmaster 





     $mailprog          = ‘/usr/lib/sendmail -oi -t’;


    sub new {

      my ($pkg, $mailprog) = @_;


      return bless { Mailprog => $mailprog }, $pkg;



     mailprog               => $mailprog,

    1. This line is indeed within the FormMail script that is linked to in this article and can be found on line 1777 by default.

  21. Thank you for figuring this out.  Unfortunately, not being a programmer, I am still unclear on what to do. I’m told by tech support that I can’t use sendmail and they suggested using a php script.  Regarding your fix for not having sendmail, where exactly do I put $mailprog = ‘SMTP:mailhost.your.domain. Somewhere on the file?


    1. Hello Liz,

      Sorry for the confusion. The file is a PERL script, but it also a simple text file that you can edit using a text editor such as the one available to you through the cPanel (checkout: Using the File Manager Code Editor).

      You would look for this line:

      $mailprog = ‘SMTP:mailhost.your.domain’;

      And replace the SMTP:mailhost.your.domain with your SMTP settings. So it would look like this:

      $mailprog = ‘’;

      I hope that helps to clarify it for you! You don’t need to be a programmer to make this kind of change. Let us know if you require any further assistance.

      Arnel C.

  22. i just filled out our real form (not our previous test form)  which has the same action script  and I got the same thing

    I entered my name in the name field and my email in the email field.  The result is the same.

    The email is still coming “[email protected],” the header is still correct which says “volunteer form” but the first line of text still says ays “Below is the result of your feedback form.  It was submitted by () on Monday, September 29, 2014 at 18:16:03”  Underneath that it does give my name and email where I filled out the form fields but I want to change the “from [email protected]” and the “It was submitted by ()”

    I don’t know why you are getting different results from me.  I am using Apple mail on a desktop computer to receive my mail.


    1. Hello Liz,

      Sorry about the confusion with the form. Scott and I have both looked at this. I discovered the cause for this as a security setting on shared servers. This security setting basically forces the “[email protected]” to appear when mail is sent without specifying a server and server – this happens with the formmail script. Luckily, you can easily fix this. Here’s the section in the FormMail readme file on using SMTP settings (that stop the nobody thing from happening):

      If your web server lacks a sendmail binary, you can
      use an SMTP relay instead, by setting $mailprog like

      $mailprog = ‘SMTP:mailhost.your.domain’;

      You will need to replace mailhost.your.domain with
      the name or IP address of an SMTP server configured
      to relay mail for the web server.

      Your system administrator or hosting provider should
      be able to tell you either the path to sendmail on the
      web server or the name of a host that will act as an
      SMTP relay for the web server.

      You can find your OUTBOUND SMTP settings by reviewing this article: How to find my email settings.

      Modify your form and then with those settings, then the Sender should be set to the Postmaster setting in your script. If you continue to have problems with it, please let us know.

      Sorry again for the headaches with the form. The setting for NOBODY is forced in order to help put a stop to SPAM issues on our servers. Forcing a sender of NOBODY when SMTP settings and sender are not verified allows us to track where the email is coming from and put a stop to illicit spam scripts that are sometimes forced on unaware account owners.

      Kindest regards,
      Arnel C.

  23. Here is the link to my sample form

    What I received is:


    [email protected]

    Volunteer Form

    Below is the result of your feedback form.  It was submitted by

    () on Monday, September 29, 2014 at 15:56:52

    name: liz

    animal: cat


    1. Hello Liz,

      I have set up a test form on my own server with the FormMail and have run a few tests. The ‘nobody@’ email address appears when the email section of the form is left blank. This is the same for the () that appears. This means that the name field was seen to be empty.

      When I put information in those fields, I receive the email and it has the content that was inserted in place of the default information (nobody@ and () ).

      Kindest Regards,
      Scott M

    1. Hello Liz,

      Sorry for the problem. Can you provide some details on what you received? We don’t see anything in your reply.

      Arnel C.

  24. I have 2 problems I’m trying to fix.

    1) I got the form to work but under the subject line it says “Below is the result of your feedback form.  It was submitted by () on Sunday, September 28, 2014 at 15:51:16”

    Shouldn’t the () show the person’s name and/or email who submitted it?  It makes no sense for it to be empty.


    2) the email I get is from “nobody@ecbiz(my server)”  This really looks like spam.  Is there a way to have it come from a name I choose?

    I’m not a programmer but if you tell me what to change in the perl script I can do that.

    Sorry if this is a duplicate.  The captcha said it didn’t work although I thought it did.

    1. Hello liz,

      Thank you for your question. 1) I looked through the README file included with the formail script, and it says the From should be pulled from the form. Meaning if they fill out the “from” field, it should be included.

      2) We are happy to help, but will need some additional information to answer this section. Is this the email you get when you fill out the form? or is this sent to you notifying you that someone else has filled out the form? Can you provide a link to the form?

      Feel free to post any additional questions below.

      Thank you,

  25. Thanks for such a quick response, that was awesome! I’m confused as to where exactly I’m to put steps 5 and 6 of the Creating a Contact Form with FormMail tut. Does it go in the Perl doc or in my Dreamweaver Contact page, where I created the html. Does it go in the head or body? Thanks again.

    1. Hello Patricia,

      The code goes into your web page – where ever your form code located. The PERL script changes are edited directly in the PL file that saved in your CGI-BIN folder. The web page is where ever you’re displaying the form where your visitors have to click and fill out the fields in order for the form mail to be sent. If you’re still confused, please let me know.

      Arnel Cl

  26. I’m fine until step 5, I have no idea where to add the code to. This is the first time I’ve been into the cPanel and really feel confused now. I’d really like to understand this a bit better. I’ve been trying to research this for about a week and just found your site. Thank you

    1. Hello Patricia,

      Sorry that you’re feeling confused. Websites are basically files on a server. In order to obtain the data for email that you want to automatically send, you need a web page that is referencing the form. The CGI-BIN is a folder on your server – this is where the script that you obtained from the zip file will need to be saved. You can use the cPanel File manager for an easy way to manipulate files on your server.

      If you need more detailed help with creating the form on your website, follow these tutorials and they’ll help you understand that portion of it: Adding Contact Forms to your website.

      Hope that helps! If you have any further questions please let us know.

      Arnel C.

  27. Hi John,


    I would like to try this to our company website but I don’t understand well how to follow the instructions correctly.

    Maybe it can help if you put also the certain line in #3 and #4 instructions to go to, to make it easier.




    1. Hello Armand,

      Thank you for your suggestion. I have created a ticket for our Support Center team, and we will be reviewing the article.

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


Was this article helpful? Join the conversation!