Form-to-Email

This script is from Matt's Script Archive, and is one of the most widely used form-to-email scripts in the world.

 



Form Action

The first step in using this form-to-email script is to set the first line of the form to be:

<form action="http://secure.datarealm.com/cgi-bin/FormMail.cgi" method="post">

 

Action - The action value gives the browser the location of the script that will process the information from this form. In this case please use: http://secure.datarealm.com/cgi-bin/FormMail.cgi

Method - The method value tells the browser how to pass the information to the script. If the value is set to "post" - the browser will pass the information silently in the background. If the value is set to "get" - the browser will pass the information in the URL. For various reasons it is advised that "post" be used unless "get" is needed for a specific process.

 

 

Form Settings

The form settings should be placed directly below the form action line. They allow you to specify exactly how the script will operate. There is only one required element, the rest are optional.



recipient (Required)

This line specifies the email address that will be sent the contents of the form. This is the only required configuration item. The email address/alias used in the recipient field, must use a domain hosted on your account (the domain of an email is the text after the @ symbol). This is required to prevent spammers from using the script to send out spam.

If you want to use more than one address, separate the email addresses with a comma. Replace you@example.com with the email address(es) that you would like to use.

<input type="hidden" NAME="recipient" value="you@example.com">

 

subject

If you would like to specify the subject of the email that the form sends, use the line below. If you do not use this option, the script will default the message subject to: WWW Form Submission

<input type=hidden name="subject" value="Form Subject">

 

email

If you want to have the visitor specify their email address, use the line below. This result will be specified in the "From:" field of the email that the form sends.

<input type=text name="email">

 

realname

If you would like the user to add their name to the email address mentioned above, use the tag below. This result will be shown in the "From:" field of the email the form sends.

<input type=text name="realname">

 

redirect

If you would like to specify the page that users are redirected to after filling out the form, use the line below. If you do not use this option, the script will use the default confirmation page.

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

required

If you would like to require the visitor to fill out certain form fields, use the tag below. place all field names that you want to be mandatory into this field. If the required fields are not filled in, the user will be notified of what they need to fill in, and a link back to the form they just submitted will be provided. If you do not use this option, the user will not be required to fill in any of the items on the form.

<input type=hidden name="required" value="email,realname,formfield3,etc">

 

missing_fields_redirect

If you want to use a custom error page to indicate when a visitor has not filled out one of the required fields, as opposed to the default, use this tag. If you do not use this option, the script will show the default error page.

<input type=hidden name="missing_fields_redirect" value="http://www.example.com/oops.html">

 

env_report

If you would like gather additional information on your visitors, specifically their ISP (REMOTE_HOST), IP Address (REMOTE_ADDR), and Browser type (HTTP_USER_AGENT), use the following tag. If you do not use this option, the script won't record any of this information.

<input type=hidden name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT">;

 

sort

If you want to specify the order that the items appear in the email, this tag can help. It has 2 options, the first will alphabetize the results, the second will sort the results in the specific manner you specify. If you do not use this option, the script will sort the results in the order they appear in the browser.

<input type=hidden name="sort" value="alphabetic">
or
<input type=hidden name="sort" value="order:item3,item1,etc...">

 

print_config

If you would like the values for the email, realname, and subject printed in the body of the message, you can use this tag to accomplish your goal. If you do not use this option, these values will appear only in the header of the message.

<input type=hidden name="print_config" value="email,realname,subject">

 

print_blank_fields

If you want all of the form fields to be included in the email, even if they are blank, use this tag. If you do not use this option, the script will not include blank form fields in the email message.

<input type=hidden name="print_blank_fields" value="1">

 

Form Confirmation Page Variables

This script will automatically generate a form confirmation page for you. The following variables allow you to customize the appearance of that page. If you are going to be using the redirect value, you won't need to set any of these variables.

 

title

This form field allows you to specify the title and header that appear on the confirmation page.

<input type=hidden name="title" value="Thank you for Signing Up">

 

return_link_url

This field allows you to specify a URL that will appear, as return_link_title, on the confirmation page.

<input type=hidden name="return_link_url" value="http://www.example.com">

 

return_link_title

This is the title that will be used to link the user back to the page you specify with the return_link_url.

<input type=hidden name="return_link_title" value="Return to example.com">

 

background

If you would like a background image on the confirmation page, this tag will let you.

<input type=hidden name="background" value="http://www.example.com/bg.gif">

 

bgcolor

This form field allow you to specify a background color for the confirmation page.

<input type=hidden name="bgcolor" value="#FFFFFF">

 

text_color

If you would like to specify the text color of the confirmation page, use the tag below. Otherwise the default text color (black) will be used.

<input type=hidden name="text_color" value="#000000">

 

link_color

If you need to change the default link color from the standard blue, you can use the tag below.

<input type=hidden name="link_color" value="#FF0000">

 

vlink_color

If you need to change the default visited link color from the standard purple, you can use the tag below.

<input type=hidden name="vlink_color" value="#FF0000">

 

alink_color

If you need to change the default active link color from the standard red, you can use the tag below.

<input type=hidden name="alink_color" value="#FF0000">

 

 

Sample Form


The following is the HTML for a small information request form that mails the results to the sales department, and displays a customized confirmation page. The comments along the way explain every setting: 

 

<!-- set the form action -->

<form action="http://secure.datarealm.com/cgi-bin/FormMail.cgi" method="post">

<!-- specify who is going to receive the message -->
<input type="hidden" NAME="recipient" value="sales@example.com"> 

<!-- set the subject of the message sent to the recipient -->
<input type=hidden name="subject" value="Information Request">

<!-- make the  email,realname,item and spending fields required -->
<input type=hidden name="required" value="email,realname,item,spending">

<!-- indicate the error page if require fields are not filled out --> 
<input type=hidden name="missing_fields_redirect" value="/oops.html"> 

<!-- put the spending and item fields are at the top of the email -->
<input type=hidden name="sort" value="order:spending,item"> 

<!-- put the email and realname in the body of the email -->
<input type=hidden name="print_config" value="email,realname">

<!-- if there are blank fields in the form, don't leave them out --> 
<input type=hidden name="print_blank_fields" value="1"> 


<!-- specify the title for the confirmation page -->
<input type=hidden name="title" value="Thank you for Signing Up"> 

<!-- specify the return link on the confirmation page -->
<input type=hidden name="return_link_url" value="http://www.example.com">

<!-- specify the text for the return link -->
<input type=hidden name="return_link_title" value="Return to example.com">

<!-- these next 4 bits specify the appearance of the confirmation page -->
<input type=hidden name="bgcolor" value="#000066"> 

<input type=hidden name="text_color" value="#FFFFFF"> 
<input type=hidden name="link_color" value="#DDDDFF"> 
<input type=hidden name="vlink_color" value="#FFDDFF"> 

<!-- form fields -->
Your name: <input type=text name="realname"> <br>
Your email: <input type=text name="email"> 
<p>

What items would you like more information on:<br>
<input type="checkbox" name="item" value="spkrs">Speakers
<input type="checkbox" name="item" value="radio">Radios
<input type="checkbox" name="item" value="dvd">DVD Players
<input type="checkbox" name="item" value="portcd">Portable CD players
<p>
To help us provide you with better information, how much are you willing to spend on any product:<br>
<select name="spending">

<option value="100">less than $100</option>
<option value="200">$100 - $200</option>
<option value="400">$200 - $400</option>
<option value="nolimit">No Limit</option>
</select>

<p>
If you have any additional comments, please enter them below:<br>
<textarea cols="25" rows="5" name="comments"></textarea>
<p>
<input type="submit" value="Request Info">
</form>

 

 

Troubleshooting

 

If you have problems with this form, please make sure to check the form settings for any possible errors. A few common errors, with straightforward fixes, are detailed below. 

 

Nothing happens when the submit button is pressed - Check the form action. Typically when the form doesn't work at all it points to a problem with the form action line. Also check your page for any other form action lines that might be confusing the browser (eg: <form>). 

 

404 File Not Found -There are two possible culprits with this error:

 

 - Incorrect form action. The browser can't find the script to process the result.

 - Incorrect redirect value (if it is being used). The browser can't find the page to redirect the visitor to.

 

Everything appears to work, but the email is never received - Check the entire recipient line. Any little typo can mix up the email address and prevent the mail from being properly delivered.

Was this answer helpful?

 Print this Article

Also Read

reCAPTCHA

Adding reCAPTCHA to your Datarealm Forms In order to limit the amount of spam submitted through...

Majordomo Subscription Form

Configure our script that allows visitors to subscribe or un subscribe to your majordomo mailing...

Perlfect Search Tool

How to install and configure the Perlfect Search script and integrate it into your website.   A...

Secure Form-to-Email

How to implement our secure form-to-email script. Our secure form protects your visitors...

WordPress

A few notes about installing WordPress :   - WordPress is a third party software. We do not...