Email Form Creation - Cpanel Servers


| Simple method | Advanced method | Securing a form | Creating a form in RV/EZ BUILDER | Using Captcha

What is a form?
Simple Method:
Cpanel has a built in form program inside it that automatically does all the work for you.  It is called smartmail.  First step is to create a HTML page like normal.  Now insert the following code into that page:

<form action="http://www.yourdomain.com/cgi-sys/smartmail.cgi" method="POST">

<input type="hidden" name="recipient" value="email@yourdomain.com">
<input type="hidden" name="subject" value="Feedback from web site">
<input type="hidden" name="redirect" value="http://www.yourdomain.com/thankyou.htm">
Email: <input type=text size=20 name=email>
Your Name: <input type=text size=20 name=realname>
Your Message: <input type=text size=20 name=message>
<input type="SUBMIT" VALUE="SUBMIT TO US">
</form>

Now replace all the code in red with your information.  The recipient field is where all emails sent from the form will go to. The redirect field will send the user to any defined URL after the form is successful. Save the HTML file.  Now run it in your browser.  You should see a form appear on your page asking you for your name, etc.

Fill it out and press submit.  It should have run without error.  If so, the message you entered will be whisked off to the email address you entered in the recipient field.  If you get an error that smartmail can't be found, try replacing the word smartmail.cgi with FormMail-clone.cgi in the code. If that STILL does not work, contact support and we'll take a look at it for you.

Advanced Method: (setting it up from scratch)
This method is much better because it gives you more flexibility.  For instance we will show you how to assure that a spammer never, ever sees your email address, even in the code of the webpage!  This method does not use the built-in form program, but instead has you install your own form processor, which is more secure.  It sounds difficult but it really is not.  (For even more security try the new <a href=captcha.html>captcha method</A>).

First step, go into your account file structure and find the directory called cgi-bin.  This is where your form processor program will go.

Now we are going to have you create a file in the cgi-bin directory called myrelay.pl (you can call it anything, but in this case we'll use myrelay.pl). Never call it formmail or smartmail cause those names are reserved.

Copy all the code located at right into this file.  If you can't see this file here click on this link.  Ok save myrelay.pl

Go back into myrelay.pl and look for the following line of code:
@referers = ('scriptarchive.com','209.196.21.3');
Replace the code in red with your domain name and your IP address.  Contact us if you do not know your IP address.  Ok save myrelay.pl again.

Second step, set the permissions on the myrelay.pl file to 755. You can use the cpanel file manager to accomplish this. Contact us if you don't know how to do this, we will gladly do it for you.

Third step: Go into your web files directory where your website resides. Create a HTML page like normal.  Now insert the following code into that page:

<form action="http://www.yourdomain.com/cgi-sys/myrelay.pl" method="POST">

<input type="hidden" name="recipient" value="email@yourdomain.com">
<input type="hidden" name="subject" value="Feedback from web site">
<input type="hidden" name="redirect" value="http://www.yourdomain.com/thankyou.htm">
Email: <input type=text size=20 name=email>
Your Name: <input type=text size=20 name=realname>
Your Message: <input type=text size=20 name=message>
<input type="SUBMIT" VALUE="SUBMIT TO US">
</form>

Now replace all the code in red with your information.  The recipient field is where all emails sent from the form will go to. The redirect field will send the user to any defined URL after the form is successful.  Save the HTML file.  Now run it in your browser.  You should see a form appear on your page asking you for your name, etc.

Fill it out and press submit.  It should have run without error.  If so, the message you entered will be whisked off to the email address you entered in the recipient field.  If not, contact support and we'll take a look at it for you.
Securing a form from spammers:
The most common use of forms is to allow users to email you without posting your email address directly on your web page (a practice which is now considered highly dangerous, just don't do it).  The above accomplishes that, however, your email address still appears in the web page code in the recipient field.  A good spammer can view the source of your web page and get the address.

Is there a way to create a form without a recipient field showing?  Oh yes.  You can hard code the recipient field in the form processor itself, where the spammer can never get it.  And its pretty simple to accomplish.

First step, go through the advanced method for setting up a form above.

Second step, replace the recipient field in your HTML page with an email alias which does not exist.  For example:

<input type="hidden" name="recipient" value="stopSPAMMING@yourdomain.com">

This is your FAKE address and this is all the spammer will ever see. Make sure to go into cpanel's email controls are set to delete random aliases.

Third step, search through the myrelay.pl file for the following code:

sub send_mail {

Underneath that line, copy the following line in:

    $Config{'recipient'} = "youremailaddress\@yourdomain.com";

Replace what's in red with the email address where you actually want your form data to go.  This is your REAL address and the spammer will never see this as it is hidden deep inside of your processor code.  Note: make sure to keep the forward slash ( \ ) before the @ symbol.  That's it you are done.
Common problems: More form techniques
The above example shows you how to create forms with simple text fields.  However you can also insert fancy fields for the user to enter data including comment boxes, radio buttons, pulldown menu's, etc.  To review these, check out this resource which gives you a tutorial on all of the html tags available inside of a form.
Creating a form automatically with RV/EZ Builder

If you have RV/EZ Builder installed into your account (contact us for more information), you can use it to automatically build a form for you. 

RV Builder Form creationTo do this, go into your builder.  Click on the site content tab.  Then click on WYSIWYG editor on the page you want to add the form to.

The editor will open and you will see the menu shown at right.  The form creator icon is on the bottom row.  It looks like a square (just to the left of the 1234 icon).