Email: Create a Contact Form using Formmail
In this article, we will show you how to setup and configure Form Mail, a perl based email script that is an excellent alternative to cPanel’s FormMail scripts. It will allow you to have the results of html forms sent to you via email.
For this article, you will need to know basic html, and ftp.
1) Download the newest copy of the Form Mail script from http://www.scriptarchive.com/download.cgi?s=formmail
2) Unzip the archive and open the FormMail.pl file using your preferred text editor (e.g. notepad).
3) Edit the following settings located at the top of the file…
locate:
$mailprog = '/usr/lib/sendmail -i -t'; |
… and replace with:
$mailprog = '/usr/sbin/sendmail -i -t'; |
Now locate:
@referers = ('scriptarchive.com','72.52.156.109'); |
… and replace with:
@referers = ('yourdomain.com'); |
Note: Make sure that you replace yourdomain.com with your actual domain name.
Once you have made the changes, save the file.
4) Using FTP, upload the saved file from step 3 to the cgi-bin for your website (normally found at public_html/cgi-bin).
5) Still using FTP, change the permissions of the FormMail.pl file to allow it to be executable (e.g. 0755). For more information about permissions and CHMOD, please click here.
6) Open the file you wish to place the contact form on and paste the following code.
<form id=”contact” name=”contact” method=”POST” action=”/cgi-bin/FormMail.pl”>
<label>Your Email: </lable><input type=text name=”email” /><br />
<label>Subject: </lable><input type=text name=”subject”/><br />
<label>Message: </lable><textarea name=”body” id=”body” cols=”45″ rows=”5″></textarea><br /><input type=hidden name=”recipient” value=”[email protected]” />
<input type=hidden name=”redirect” value=”http://yourdomain.com/thankyou.html“/>
<input type=”submit” name=”button” id=”button” value=”Send” /></form>
Now we will cover what each line does…
<label>Your Email: </lable><input type=text name=”email” /><br />
This line is where they would input their email so you can reply to them.
<label>Subject: </lable><input type=text name=”subject”/><br />
This gives them the option to input a subject for their email.
<label>Message: </lable><textarea name=”body” id=”body” cols=”45″ rows=”5″></textarea><br />
Here is where they can type a message.
<input type=hidden name=”recipient” value=”[email protected]” />
This is where the email will be sent. Please keep in mind that the domain for the email must be in the @referers section of line 3.
<input type=hidden name=”redirect” value=”http://yourdomain.com/thankyou.html“/>
This line allows you to change where they are redirected after the email has been sent. For example, you could redirect them to a “Thank You” page letting them know their email was sent.
<input type=”submit” name=”button” id=”button” value=”Send” />
This is the button that sends the form. You can change the button text by modifying the value.
That’s it! You now know how to use Form Mail. For more detailed information about what you can do with this form processeser, please read the README file located in the zip file downloaded in step 1. Remember to change the items in bold above to fit your needs.
Al Guevara August 25, 2013 at 1:02 pm
Why are you all using/publishing a script that hasnt been updated in 4 years?
John Oliver at Site5 August 27, 2013 at 4:22 pm
Hello Al,
Thank you for the great comment!
The Formmail software we used in this article, while old, is still a powerful form processer that many people still use.
We are in the process of putting together a PHP form processer that we will release on the KnowledgeBase soon.
If you have any other questions, please feel free to leave a reply here, or if you prefer, you can contact our support team directly by opening a ticket through Backstage.
Happy Hosting!
Al Guevara November 22, 2013 at 7:20 pm
I beg to differ John. Any form script that exposes the email address is ancient, and weak at best.
Tectite has a very secure php form for free.
http://www.tectite.com/fmdoc/index.php
One only need to configure 2 settings for it to work. Yet the Tectite php script has a HUGE array of options for both security and receiving convenience.
It also offers a paid online configurator for $10. Gives you two days make all the forms you want. The form is free, you paying for the convenience of the auto configuration.
http://www.tectite.com/wizards/choose.php
Spits out 3 forms one can use, and the ready to go Tectite script.
For the experienced, free download, and self-configure.
http://www.tectite.com/formmail.zip
James Davey November 23, 2013 at 8:18 am
Hello Al,
Thank you for passing that along. However, we are not stressing the use of FormMail over any other script – this is a question that comes up often in our support department from customers, and we have written this guide as a way to help. This is not us telling people to use FormMail, but simply helping those of our customers who choose to do so.
Mark K December 3, 2013 at 4:54 am
Please avoid using this formmail. It’s a scam.
I installed this script. When you submit, it will take you to another website.
Please avoid at all cost. Moderator, please try it out and delete Al’s post.
Al Guevara December 5, 2013 at 2:34 am
You simply didn’t configure the “results page.” So take that!
Alvaro Guevara March 17, 2014 at 5:19 pm
I see nothing wrong witht he links, they are all Tectite.
Glenn Wells June 25, 2014 at 10:42 am
James,
Regardless of the lack of security and other shortcomings, we know that site owners continue to use this script and others like it. We warn our clients not to use any of these. We use an internally-developed ISAPI application that encodes the sender’s email address and posts the sender’s message directly to a database on our server (if the filters show it is not spam).
We would expect and hope to see more of these types of solutions in the future.
James Davey June 25, 2014 at 10:56 am
Hi Glenn,
That is fine, yes. As mentioned elsewhere here, having this guide is not a tacit suggestion to use this script. We have many customers who ask about this script specifically, and we put this guide together to aid them. All of our customers are free to use whatever form script they wish to use, provided it works on our servers (and most do).
justin hull October 16, 2013 at 11:45 am
I am beginning the process of adding a simple custom order form to my website to handle some initial order processing.
I reviewed the KB and jsut anted to ask if this form is customizable? I woudl want to add some other input fields and have a label be part of the form. Can we use other scripts and a custom php.ini file?
John Oliver at Site5 October 17, 2013 at 6:13 pm
Hello Justin,
I hope this reply finds you well!
You can add as many fields as you wish to the HTML form. Simply format them like you would any other form field.
If you have any questions, please feel free to leave a comment here, or if you prefer, you can contact our support team directly by opening a ticket through Backstage.
Melissa Morrow November 22, 2013 at 12:45 pm
I think the correct tag is “label” not “lable”, right?
James Davey November 22, 2013 at 2:13 pm
Hi Melissa,
You are correct, yes, and this has been edited accordingly. Thanks for pointing that out!
Reony Tonneyck December 4, 2013 at 10:18 am
Is there any kind of phishing/spam protection on this? I want to change my form mail to this one, but the problem with my old one is that I’m always getting spam/bot mail from it.
James Davey December 4, 2013 at 10:39 am
Hello Reony,
Not by default, no. But you can certainly add a CAPTCHA to your form to help with this – http://www.google.com/recaptcha/captcha
This forces your form to be used by a human rather than a bot.
Reony Tonneyck December 4, 2013 at 11:46 am
Oh right! Thanks for reminding me about this. I think when I tried it once in the past I couldn’t get it to work with my current form template. Maybe if I use your Form mail with this it will.
Usaha Simple January 9, 2014 at 7:03 am
Inspiring!, Thanks for the info…. Cheers :)
Jabo February 22, 2014 at 10:14 am
Why do you use a script that displays your email address for spammers to get?
John March 1, 2014 at 6:40 pm
Is there an input field to have a user upload a file, and how would the file be handled (i.e. mailed with form as an attachment, loaded to a sub-directory, etc)?
James Davey March 3, 2014 at 8:06 am
Hi John,
Not with this formmail script, no. At least, not by default. I am sure you could add the code for this, but I am not certain how well it would work. For something like that, I would recommend looking for another form script with that functionality built-in.
sjbhijacked March 16, 2014 at 2:16 pm
I did not think you could use recaptcha with html but had to be php
I have php email script but client has users that always put double and single quotes in the comment box that are legitimate and relevant to commenting on sizes in feet and inches but the email response the get replaces the double quotes and single quotes with html entities…I have tried using htmlentities in the php script to allow the quotation marks to no avail.
James Davey March 17, 2014 at 9:05 am
That does sound quite strange, but there is nothing server-side that would cause that, that I am aware of. That would be in the code itself, and something you may want to have a developer look at.
Wordpress Plugin August 27, 2014 at 6:47 am
Hi John Oliver,
Can the Contact Form validate E-mail and Physical Address the users type in?
James Davey August 27, 2014 at 7:14 am
Hi there,
I am not entirely sure what you mean. Are you asking if the form script will confirm an accurate email and physical address when entered, to ensure it is correct? If so, no, this will not happen. I am sure it could be done, but not with this simple script – the code to do this would be large and quite complicated.
Wordpress Plugin August 28, 2014 at 6:16 am
Hi James,
Thank you for your reply. That was what I was asking about.
Daniel @ Status Page March 14, 2015 at 7:29 am
Nice guide and form mail seems really easy to use.