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="" 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:

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 with the email address(es) that you would like to use.

<input type="hidden" NAME="recipient" value="">



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">



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">



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">



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="">


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">



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="">



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">;



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">
<input type=hidden name="sort" value="order:item3,item1,etc...">



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">



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.



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">



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="">



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">



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

<input type=hidden name="background" value="">



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

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



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">



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">



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">



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="" method="post">

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

<!-- 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="">

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

<!-- 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"> 

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
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>

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





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


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


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

Secure Form-to-Email

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

The Counter

Instructions for setting up and configuring a basic page visit counter.   Installing the...

Perlfect Search Tool

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