Form2Email
Form2Email - Anti SPAM Form to Email
A visitor inputs the data using a form on your website, they click send and the data is sent to the script, the script then uses sendmail to send you an email and write the data to the log. The visitor is sent to a new web page.

» Things you have to do
» Things you will need
» Features of the scripts
» Create the form on your website
» Set-up the script
» Create the Thank You page

» Create the log on your website
» Using the Admin mode to view emails
» Security Advice when using Form2Email.net



Things you will need

1) A website!
2) FTP Software like CUTE FTP to upload files
3) Web server running Perl (5.006 or higher) and Sendmail (ask your host)
4) Form2Email script (download from this website)
5) Webpage with a form (download sample from this website)
6) Thank you page (any standard web page)

Back to Top


Things you have to do

1) Follow the instructions below
2) Download the Form2Email  script and make a few changes
3) Create a form on your website
4) Create a 'thank you' page
5) Upload the script and webpages with FTP and CHMOD the Script 755

Back to Top


Features of the scripts

Form2Email.net Script Features  
No adverts or links in the script YES
Instant download YES
Send data from almost any web form YES
Hide your email address from SPAM bots YES
Security to stop SPAM being sent using script YES
Redirect users to any web page after sending data YES
Send the data by email using sendmail YES
Send the data by email using SMTP YES
Check form for required fields with text, numbers or email YES
Write the date, users IP address & Browser details YES
Use image as 'GO' button rather than HTML YES
Support for unlimited email addresses  YES
Support for unlimited redirect locations YES
Support for unlimited subjects YES
Option to change the from email address to users YES
Upload files to your web server and link in emails YES
Send an auto responder to the visitor YES
Keep a log of the emails  YES
Administrator mode for reading the log  YES
Password protection for the admin mode  YES

Back to Top


Create the form on your website

When you download the script you will find a sample form, if you are new to forms then get this sample form running first. If you are putting the script in your cgi-bin then the form action in the sample form will be correct, if not you will need to edit the form.

The form action is the URL of your script, so each form will need to start with: <form method="POST" action="/cgi-bin/form2email.pl">

Then end with:
<input type="submit" value=" [ send ] ">
</form>
Your fields are in the middle.

Example Code for a basic webform:



That's everything you need to get your form running. You don't need to change anything else unless you want to use the advanced features.

Change the send button for an image
You can change the send button for an image.
Change line: <input type="submit" value="SEND">
For this: <input type="image" src="send.gif">

Alternative 'thank you page' and email address feature
If you are using the advanced features to use different templates and thank you pages with the same script you will need to add the code into your form.

To use the 'thank you page' you put for 'thankyou1' with a hidden form field:
<input type="hidden" name="ThankYouPage" value="thankyou1">

To use the email address you put for 'email1' with a hidden form field:
<input type="hidden" name="SendToAddress" value="email1">

As part of a drop-down menu your code would look like this:


Using the form for required fields

You have two ways to set the required fields. Either in the script, ideal if you have just one form. Or using the form, ideal if you have many forms using the script. Required field name must have no spaces or special characters.

Set the field names in your form that require data. The script can check for any data, just numbers or just an email address.

<input type="hidden" name="required_fields" value="field,name">
<input type="hidden" name="required_fields_numbers" value="field,name">
<input type="hidden" name="required_fields_email" value="field,name">


Using the file upload feature

If you are using the file upload feature you must check with your host that your server will allow forms with "multipart/form-data".

The script will put the file in your chosen directory and add the file URL to the log and your email.

You will need to change your input form, forms with upload must start with
<FORM action=form2email.pl method=post ENCTYPE="multipart/form-data">

To add a field for the upload and add the browse button add the code below, you can have as many file uploads as you need in each form.
<input type="file" name="fieldname">

Back to Top


Set-up the script

Form2Email.net
(Current Version: 13/September/2005)

Check your path to perl
#!/usr/bin/perl

Change this to the name of your script.
my $script_name = 'form2email.pl';

Change the FULL URL of your thank you page on your website
my $HTML_thankyou = 'http://www.your-website-url.co.uk';

Change the email address you would like the email to go to
my $to = 'YourEmail@your-website-url.co.uk';

Change this to the email address you would like the email to be from
my $from = 'YourEmail@your-website-url.co.uk';

This is the PATH to your send mail (check this with your administrator)
my $mailprog = '/usr/sbin/sendmail';

Change this to the subject you would like in your emails
my $subject = 'Web Enquiry from www.your-website-url.co.uk';

That's everything you need to get your script running. You don't need to change anything else unless you want to use the advanced features.

Advanced Settings Log details

If you want to keep a log of the emails '1' to log '0' for no log.
my $log = '1';

Change the PATH of your log, the first time the script is run it will create the database for you. On most server you can use just the file name.
my $log_name = '/path/to/mylog.txt';

This is the seperator between the emails. It is not seen and can be anything.
my $seperator = '##### log #####';

If you wish to record just the data and not the field names change this to '1'
my $data_only = '0';

Advanced Settings Admin Mode Password

You can change the 'admin' mode name to anything you like, so mode=admin can be any 'word' that you choose it to be.
my $admin_mode = 'admin';

Change this to your username and password for the admin mode. You can leave them blank if you don't want to use this feature.
my $username = "username";
my $password = "password";

Advanced Settings

If you want to use an image rather than the HTML send button change this to 0 to allow an image or 1 not to allow the image button.
my $kill_image_buttons_value = 1;

To stop users sending HTML set this to 1, or 0 to allow HTML
my $kill_html_tags = 1;

To have the 'subject' use a value of a field in the form then change this to the field name that will have that value.
my $subject_field = "subject";

You can limit the size of the message sent. This will restrict a visitor posting large amounts of data in an attempt to send SPAM. 
my $max_message_length = 300;
my $max_message_error = "Sorry, your message is to big";

Set this to 1 if you want just data by email and not the field names.
my $send_just_data = 0;

Advanced Settings From Field Name

You can change the email address the message is from to an email address use in the form, if a user leaves this blank it will use the default address.

my $from_field_name = 'fieldname';
my $from_field_name_error = "Data Error in $from_field_name";

Advanced Settings Auto Responder

If you have set the 'from' field to be a required email address then you can send a text auto responder to the user.

Change the '0' to '1' to switch on this feature and set the subject, plus the full PATH to the text file to send as the message to user.

my $auto_responder = 0;
my $auto_responder_from = 'Somebody@your-website-url.co.uk';
my $auto_responder_message = "/path/to/the/message.txt";
my $auto_responder_subject = "Email from your-website-url.co.uk";

Advanced Settings Environmental values

If you don't wish to know the users IP address, Browser information and the Date change the '1' to '0'.

my $REMOTE_ADDR = 1;
my $HTTP_USER_AGENT = 1;
my $DATE = 1;

Advanced Settings SMTP 

To use SMTP rather than sendmail remove the hash and space
# use Net::SMTP;

If you wish to use SMTP rather than SENDMAIL set this to '1'
my $send_via_SMTP = 0;

Your SMTP server details (check this with your administrator)
my $mailhost = 'smtp.com';

Advanced Settings required fields 

You have two ways to set the required fields. Either in the script, ideal if you have just one form. Or using the form, ideal if you have many forms using the script. Required field name must have no spaces or special characters.

If you wish to use the script to list your required fields set this to 0
If you wish to use the form then then set this to 1
my $required_fields_form = 0;

Set the field names in your form that require data. The script can check for any data, just numbers or just an email address. If you have set-up the script to use the form to list the fields then just leave this section blank.

ALL fields required to have data. Leave as () if none are required.
(Ensure they are the same name as your form)
my @required_fields = (fieldname,fieldname,fieldname);

The fields required with numbers. Leave as () if none are required.
(Ensure they are the same name as your form)
my @required_fields_numbers = (fieldname,fieldname);

The fields required with an email address. Leave as () if none are required. (Ensure they are the same name as your form)
my @required_fields_email = (fieldname,fieldname);

Advanced Settings required fields errors

You can customize the error message and format a customer will see if they do not input your required fields. You can add HTML but do not any quote marks in the code.  One exception is the $error_fields_forbidden option, which is the message spammers get when they try to include commands to the mail server to spam other people...

my $error_fields_require = "Field is blank, it is required";
my $error_fields_numbers = "Only numbers";
my $error_fields_email = "email address is not valid";
my $error_fields_forbidden = "Forbidden field name";
my $error_title = "<b>Sorry, we require more information</b>";
my $fontColor = "black";
my $fontSize = 3;
my $fontFace = "Verdana";
my $return_message = "Please click 'back' on your browser";

Advanced Settings extra email address & 'thank you' page

If you want to use the same script but use a different email address or thank you page you can. You put the location of the files in the script rather than in your form this will reduce your SPAM. You can have as many as you like.

$HTML_thankyou_field_name = 'ThankYouPage';
$ThankYou{'thankyou1'} = 'http://www.your-website-url.co.uk/';
$ThankYou{'thankyou2'} = 'http://www.your-website-url.co.uk/';
$ThankYou{'thankyou3'} = 'http://www.your-website-url.co.uk/';
$ThankYou{'thankyou4'} = 'http://www.your-website-url.co.uk/';
$ThankYou{'thankyou5'} = 'http://www.your-website-url.co.uk/';
$ThankYou{'thankyou6'} = 'http://www.your-website-url.co.uk/';

$field_name_email = 'SendToAddress';
$SendTo{'email1'} = 'email@your-website-url.co.uk';
$SendTo{'email2'} = 'email@your-website-url.co.uk';
$SendTo{'email3'} = 'email@your-website-url.co.uk';
$SendTo{'email4'} = 'email@your-website-url.co.uk';
$SendTo{'email5'} = 'email@your-website-url.co.uk';
$SendTo{'email6'} = 'email@your-website-url.co.uk';

Your form could then contain directions on which thank you page or email address to use.  e.g. :

<input type="hidden" name="ThankYouPage" value="thankyou3">
<input type="hidden" name="SendToAddress" value="email5">

Advanced Settings file upload

If you are using the file upload feature you must check with your host that your server will allow forms with "multipart/form-data".

The fields in your form that will have files to upload
my @file_upload_fields = ("fieldname","fieldname");

If you want the script to re-name the file. Strongly recommended.
my $rename_file = 1;

The maximum size of file allowed.
my $max_size = 100000;

Types of files allowed. Do not allow .exe files on your server, or leave blank.
my @required_file_types = ("txt", "jpg", "jpeg", "tif", "gif");

Errors for wrong file type and files too large
my $error_max_size = "Your file is too big!";
my $error_file_type = "File type is not valid!";

The PATH not URL to the folder to take the files without the final /. Your host may block all or some folders from taking files.
my $file_dir = "/home/path/to/your/file/folder";

The URL not PATH to the folder to take the files without the final /. Your host may block all or some folders from displaying files.
my $file_URL = "http://www.your-website-url.co.uk/files";

File size is set to bytes, to set to KB change 0 to 1
my $useKb = 0;

Back to Top


Create the 'Thank You' page

The 'Thank You' page has no special requirements. You can use any page on your website.

This page must be in a public directory, some servers don't let you put the 'thank you' page in the cgi-bin. To test this simply type the URL into your browser and if you can see the page then it is in the right location.

Back to Top


Create the log on your website

If you have set the script to keep a log of your emails you don't need to do anything more as the script will make the log for you.

However, if your server will now allow this then simply make a normal text file with the same name as the log and upload it to the same location as the script. Ensure you CHMOD it 755 (777 on some servers)

Back to Top


Using the Admin mode to view emails

To access the admin mode simply type in the full URL of your script in your browser then add ?mode=admin You can change 'admin' to any word you like. http://www.your-website-url.co.uk/cgi-bin/form2email.pl?mode=admin

You can now view and delete emails from the database. It is recommended that you keep this log below 1mb to ensure it's smooth running.

The administration mode is not suitable for use like 'hotmail' to read your emails on public computers. It is designed as an administrators tool to keep a log of your emails for printing and viewing online. 

Back to Top


Security Advice when using Form2Email.net

Criminals sending illegal SPAM messages use other peoples websites like yours to send millions of emails everyday.

The SPAM messages would have your servers IP address, users receiving the emails can trace this back to you and your website.

To find Form to Email scripts on the internet the criminals use software on their computer to scan the internet, once they have found one they will try using it to send SPAM messages.

The first step in stopping this is to use the Form2Email.net script, or any good Form to Email script that has Anti-SPAM filters built into it.

You can take some basic steps to help increase the security on your website and stop the Criminals testing your website.

1) Do not name your script form2email.pl use a random word.
2) Change the name of the log.txt to a random file name.
3) Change the mode=admin to a random word.
4) Don't use the default username and password, change it.
5) The admin mode is not suitable for public computers
6) Check for the latest version of the script, download it and update.

Back to Top

 
 

home | rate the scripts | community support forum | © www.ezscripting.com