Jack's Scripts

Mail code script email | contact form php | Formmail | Form Mail Script | Email form to html Mail PHP | Form to email | Email form php | Form to mail | Form to mail Guide
Home of Jack's Formmail.php
Bookmark and Share Bookmark and Share Email deliverability optimization

Delivery Watch - Form to email and Much more!

Need quality web hosting?



Mailing List

Enter your email address to receive an email alert when a new version of formmail is released.



Please Donate to keep this site live

Any amount would be great! :)


Form to mail | php to mail Toturial

1. Copyright
2. Overview
3. Setting Up the FormMail Script

4. Form Configuration

5. History
6. Final Comments


COPYRIGHT

PLEASE DO NOT REMOVE THE HEADER!!!

Copyright 2000-2009 Dtheater.com © All rights reserved.
http://www.dtheatre.com/scripts

This cannot and therefore will not be inforced but I would appreciate a link back to any of these sites:
http://www.dtheatre.com With the following linking words: "Movie News"
http://www.dtheatre.com/scripts/ With the following linking words:"Form to email"
http://www.dtheatre.com/TV/ With the following linking words:"Satellite TV Software"

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For full disclaimer and warranty info GO HERE.

OVERVIEW

Jack's FormMail.php is a universal WWW form to E-mail gateway. There is very few required form input tags which must be specified in order for this script to work with your existing forms. Other hidden configuration fields can also be used to enhance the operation of FormMail.php on your site.

SETTING UP THE FORMMAIL SCRIPT

To set up the FormMail.php script copy it into the directory in which you are planning to use it. It's that plain and simple.

For security reasons, it helps to rename the to something other than 'formmail.php'

Recommended Variables*

*While these variables are not required they are highly recommended.

Field:

Referers

Description:

This array allows you to define the domains that you will allow forms to reside on and use your FormMail.php script. If a user tries to put a form on another server, that is not the specified domain or ip, they will receive an error message when someone tries to fill out their form.

Further Explaination:
By placing dtheatre.com in the referers (as in the example below) array, this also allows www.dtheatre.com, ftp.dtheatre.com, dtheatre.com/dir/file/, any other http address with dtheatre.com in it and dtheatre.com's IP (216.64.145.194) address to access this script as well, so no users will be turned away.

NOTE: This is not a security check. Referer headers can EASILY be faked. Rather, it prevents someone on xyznotyou.com from using the FormMail.php on your server to process forms on their server on a regular basis. It remains in the script as a remnant of earlier versions when it was used for security, but the $recipient variable is now recommended to specify exactly who can receive e-mail from this installation.

Syntax:

$referers = ('dtheatre.com','216.64.145.194');

Notes: This is only supported in Version 3.0 or higher.


Field:

Recipient

Description:

This variables allows you to specify to whom you wish for your form results to be mailed. For Multiple Recipients seperate the email addresses with commas (",").

Due to a storm of problems related to scum abusing peoples formmail.php installations, I now recommend this option to all formmail users.

Note: If you use this option you cannot use recipient.

Syntax:

$recipient = "jack@schitt.org, steve-o@jackass.com";


Field:

Bcc

Description:

This variables allows you to specify to whom you wish for your form results to be Blind Carbon Copied to. For Multiple Recipients seperate the email addresses with commas (",").

Due to a storm of problems related to scum abusing peoples formmail.php installations, I now recommend this option to all formmail users.

Note: If you use this option you cannot use bcc.

Syntax:

$bcc = "jack@schitt.org, steve-o@jackass.com";


Optional Variables

Field:

Banlist

Description:

This array allows you to define the domains and emails that you would like banned from using your Formmail.php.

Further Explaination:
By placing *@hotmail.com it bans any one with anything@hotmail.com from using the form so if spammer@hotmail.com uses your script he'll be turned away. You can also specify an full email address, such as jack@schitt.org and only that email address will be banned not everyone at "schitt.org".

Syntax:

$banlist = array ('*@somedomain.com', 'user@domain.com', 'etc@domains.com');

Notes: This is only supported in Version 4.1b or higher.


Your formmail program is now configured.


FORM CONFIGURATION

The action of your form needs to point towards formmail.php (obviously).

ie: <FORM ACTION="formmail.php" METHOD=POST>

or if you are doing uploads..

<FORM ENCTYPE="multipart/form-data" ACTION="formmail.php" METHOD=POST>
get it? I hope so!

Now we will take you through a list of form fields you can use and how to implement them.

Necessary Form Fields

There is only one form field that you must have in your form, for FormMail.php to work correctly. This is the recipient field.

Field:

recipient

Description:

This form field allows you to specify to whom you wish for your form results to be mailed. Most likely you will want to configure this option as a hidden form field with a value equal to that of your e-mail address.

Before using this variable please read this.

Syntax:

<input type=hidden name="recipient" value="email@your.host.com">

Ver 3.0: For Multiple Recipients seperate the emails with commas (",").



Optional Form Fields

Field:

recipient

Description:

This form field allows you to specify to whom you wish for your form results to be Blind Carbon Copied to. Most likely you will want to configure this option as a hidden form field with a value equal to that of your e-mail address.

Before using this variable please read this.

Syntax:

<input type=hidden name="bcc" value="email@your.host.com, alias@myhost.com">

Ver 3.0: For Multiple Recipients seperate the emails with commas (",").


Field:

subject

Description:

The subject field will allow you to specify the subject that you wish to appear in the e-mail that is sent to you after this form has been filled out. If you do not have this option turned on, then the script will default to a message subject: "Form Submission"

Syntax:

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


Field:

email

Description:

This form field will allow the user to specify their return e-mail address. If you want to be able to return e-mail to your user, I strongly suggest that you include this form field and allow them to fill it in. This will be put into the From: field of the message you receive. The email address submitted will be checked for validity.

Syntax:

<input type=text name="email">


Field:

phone_no

Description:

This form field will allow the user to specify a phone number.
The phone number submitted will be checked for validity and must match one of the following formats.

  • 123.123.1234
  • 123-123-1234
  • (123)123.1234
  • (123)123-1234
  • etc..
Syntax:

<input type=text name="phone_no">


Field:

fax_no

Description:

This form field will allow the user to specify a fax number.
The fax number submitted will be checked for validity and must match one of the following formats.

  • 123.123.1234
  • 123-123-1234
  • (123)123.1234
  • (123)123-1234
  • etc..
Syntax:

<input type=text name="fax_no">


Field:

zip_code

Description:

This form field will allow the user to specify a zip code. The zip code submitted will be checked for basic validity and must match one of the following formats.

  • 12345
  • 12345-1234
  • A1B 2C3 (for candians :P)
Note: Only Versions 3.0 and higher support Canadian Postal Codes.
Syntax:

<input type=text name="zip_code">


Field:

redirect

Description:

If you wish to redirect the user to a different URL, rather than having them see the default response to the fill-out form, you can use this hidden variable to send them to a pre-made HTML page or as another form type to let the user decide.

Syntax:

To choose the URL they will end up at:
<input type=hidden name="redirect" value="http://your.host.com/to/ file.html">

To allow the user to specify a URL they wish to travel to once the form is filled out:
<input type=text name="redirect" value="http://">

Other options include drop down menus and radios etc..


Field:

require

Description:

You can now require for certain fields in your form to be filled in before the user can successfully submit the form. Simply 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.

(To use a customized error page, see missing_fields_redirect)

Syntax:

If you want to require that they fill in the email and phone fields in your form, so that you can reach them once you have received the mail, use a syntax like:
<input type=hidden name="require" value="email,phone_no">

You can use this on any field.


Field:

required

Description:

Required is an alias for require,

Because I was unaware that Matt Wright used "required" for the same purpose I originally used "require". A lot of people had problems with that, so I have made an alias. (Note: this is only in Version 3.0 or higher.)

see: require

Syntax:

<input type=hidden name="required" value="email,phone_no">


Field:

attachment

Description:

Allows the user attach a file to the email sent by Formmail.php.

REQUIRED

If you are using the attachment option it is crucial to include the ENCTYPE="multipart/form-data" in the form field.
Example Here

RECOMMENDED

MAX_FILE_SIZE - (case sensitive) hidden field must precede the file input field and it's value is the maximum filesize accepted. The value is in bytes.

Note: This feature was added in version 5.0

Syntax:

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

<input type="file" name="attachment">


Field:

file

Description:

Allows the user to upload a file to a path of your specification.

REQUIRED

If you are using the file option it is crucial to include the ENCTYPE="multipart/form-data" in the form field.
Example Here

path_to_file - This is the path which the file will be uploaded to. Must be a direct path to your directory. ie: "/www/yourname/filedir/"

RECOMMENDED

MAX_FILE_SIZE - (case sensitive) hidden field must precede the file input field and it's value is the maximum filesize accepted. The value is in bytes.

Syntax:

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

<input type="hidden" name="path_to_file" value="/www/dir_where_file_goes/">

<input type="file" name="file">


Field:

file2

Description:

I received a lot of email asking how to handle additional file uploads, I added "file2" to show how easy it is:
Keep the same syntax as above, but append a "2" to the end of the file.

Advanced: to add addtional files copy the php functions (below) that handle the file upload for file2 and and change the "2"s to a "3" or anything else.

The PHP:

  • click here

  • Field:

    sort

    Description:

    This field allows you to choose the order in which you wish for your variables to appear in the email that Formmail.php generates. You can choose to have the field sorted alphabetically or specify a set order in which you want the fields to appear in your mail message. By leaving this field out, the order will simply default to the order in which the browsers sends the information to the script (which is usually the exact same order as they appeared in the form.) When sorting by a set order of fields, you should include the phrase "order:" as the first part of your value for the sort field, and then follow that with the field names you want to be listed in the email message, separated by commas.
    Note: This feature was added in version 5.0

    Syntax:

    To sort alphabetically:
    <input type=hidden name="sort" value="alphabetic">

    To sort by a set field order:
    <input type=hidden name="sort" value="order:name1,name2,etc...">


    Field:

    env_report

    Description:

    Allows you to have Environment variables included in the e-mail message you receive after a user has filled out your form. Useful if you wish to know what browser they were using, what domain they were coming from or any other attributes associated with environment variables. The following is a short list of valid environment variables that might be useful:

    REMOTE_HOST
      - Sends the hostname making the request.
    REMOTE_ADDR
      - Sends the IP address of the remote host making the request.
    HTTP_USER_AGENT
      - The browser the client is using to send the request.

    Syntax:

    If you wanted to find the remote host and browser sending the request, you would put the following into your form:
    <input type=hidden name="env_report" value="REMOTE_HOST, HTTP_USER_AGENT">

    Seperate by commas ",".


    Field:

    title

    Description:

    This form field allows you to specify the title and header that will appear on resulting pages if you do not specify a redirect URL.

    Syntax:

    If you wanted a title of 'Feedback Form Results':
    <input type=hidden name="title" value="Feedback Form Results">


    Field:

    missing_fields_redirect

    Description:

    This form field allows you to specify a URL that users will be redirected to if there are fields listed in the required form field that are not filled in. This is so you can customize an error page instead of displaying the default.

    Note: Version 5.0+ appends a ?error=error message for custom error messages.

    Syntax:

    <input type=hidden name="missing_fields_redirect" value="http://your.host.com/error.html">


    Field:

    background

    Description:

    This form field allow you to specify a background image that will appear if you do not have the redirect field set. This image will appear as the background to the form results page.

    Syntax:

    <input type=hidden name="background" value="http://your.host.xxx/ image.gif">


    Field:

    bgcolor

    Description:

    This form field allow you to specify a background image that will appear if you do not have the redirect field set. This image will appear as the background to the form results page.

    Syntax:

    For a background color of White:
    <input type=hidden name="bgcolor" value="#FFFFFF">


    Field:

    text_color

    Description:

    This field works in the same way as bgcolor, except that it will change the color of your text.

    Syntax:

    For a text color of Black:
    <input type=hidden name="text_color" value="#000000">


    Field:

    link_color

    Description:

    Changes the color of links on the resulting page. Works in the same way as text_color. Should not be defined if redirect is.

    Syntax:

    For a link color of Red:
    <input type=hidden name="link_color" value="#FF0000">


    Field:

    vlink_color

    Description:

    Changes the color of visited links on the resulting page. Works in the same way as link_color. Should not be defined if redirect is.

    Syntax:

    For a visited link color of Blue:
    <input type=hidden name="vlink_color" value="#0000FF">


    Field:

    alink_color

    Description:

    Changes the color of visited links on the resulting page. Works in the same way as link_color. Should not be defined if redirect is.

    Syntax:

    For a active link color of Blue:
    <input type=hidden name="alink_color" value="#0000FF">


    Field:

    style_sheet

    Description:

    Specifies the path to a style sheet (css) that you would like to include.(Note: this is only in Version 4.0 or higher.)

    Syntax:

    <input type=hidden name="style_sheet" value="style.css">


    Auto-Responder Options

    Field:

    ar_file

    Description:

    This optional field should be the path to your a text file which contains your autoresponse text.

    Syntax:

    <input type="hidden" name="ar_file" value="/www/dir_where_file_goes/autoresponder.txt">

    Note: This is only supported in Version 5.0 or higher.


    Field:

    ar_subject

    Description:

    The ar_subject field will allow you to specify the subject that you wish to appear in the auto-response e-mail that is sent to the user after this form has been filled out. If you do not have this option turned on, then the script will default to a message subject: "Re: Form Submission"

    Syntax:

    <input type="hidden" name="ar_subject" value="Thank you for your interest">

    Note: This is only supported in Version 5.0 or higher.


    Field:

    ar_from

    Description:

    The ar_from field allows you to specify which email address is the auto-response email is sent from.

    Syntax:

    <input type="hidden" name="ar_from" value="webmaster@thisserver.com">

    Note: This is only supported in Version 5.0 or higher.


    OTHER

    To add multiple selection fields simply append a "[]" to the end of a field name.

    ie: (for checkboxes)

        Option 1: <input type="checkbox" name="multi_field[]" value="option 1"><br>
        Option 2: <input type="checkbox" name="multi_field[]" value="option 2"><br>
        Option 3: <input type="checkbox" name="multi_field[]" value="option 3"><br>


    ie: (for multiple selection fields)

       <select name="multi_field[]" size="3" multiple>
        <option>Option 1</option>
        <option>Option 2</option>
        <option>Option 3</option>
        <option>Option 4</option>
        <option>Option 5</option>
       </select>


    Note: This feature was added in version 4.0



    HISTORY


    Version 5.0 - 10/28/2003
  • added Mime Attachments and the attachment field
  • added a auto-responder feature
  • added a sort feature
  • added a bcc field
  • updated 'email' ereg from {2,3} to {2,6} for .name, .info etc..
  • if file already exists allow more than one new (for uploads)
  • changed missing_field_redirect to pass errors to next script (ie: errors.php?error=$error)
  • added defined variables for seperator and newline
  • made minor adjustments to the reserved_keys array
  • other minor adjustments/code clean-ups


  • Version 4.1b - 08/06/2001
  • added second file field
  • made referer check cAsE-inSeNsItive
  • if no referer return false (security)
  • fixed the stupid bug in "Reply-To:"
  • if file already exists we append a ".new" (for uploads)
  • check the file size (if it's 0 bytes do not attempt to upload)
  • added an email banlist.


  • Version 4.0 - 03/22/2001
  • added 'redirect' and 'email' to reserved keywords
  • added a version number variable (trivial change)
  • added $style_sheet option which allows you to specify as style sheet to use
  • now handles multiple selection fields
  • redirect now check supports *.domain.com (early bug)
  • moved print_error function to the top of the script for PHP3 users


  • Version 3.0 - 11/12/2000
  • Added Support for Canadian Postal Codes
  • Added Referer Security (see: referers)
  • Added MAX_FILE_SIZE to reserved words (minor fix)
  • Now supports multiple recipients (see: recipient, thanks to Brad Miller for pointing this out).
  • I had to add an alias to require because most people who were used to Matt's Formmail were getting confused.


  • Version 2.0 - 08/30/2000
  • Added Upload capabilities and File field etc...


  • Version 1.1a - 07/15/2000
  • Fixed the Required Fields Issue (thanks to Gard Paulsen for pointing it out).


  • Version 1.0a - 07/10/00
  • This script was created and released.