Software > Form Emailer

Form Emailer - 1.2 - Download

Overview

This was a little script I put together several years ago for a client which I've recently (Oct 2006) updated to add a little more control. The idea is very simple: to email the contents of any web form to a person or persons. All you need to do is upload the script to your website, make a few tweaks to your web form and the script and you're all set.

Additional options added in version 1.1 include:

  • Optional "receipt" email sent to person submitting the form.
  • Complete control over the contents and appearance of the email sent by defining your own text file with "placeholder".
Before reading further, you may also want to take a look at my free Form Tools script. Form Tools provides the same functionality - emailing of form submissions - but it also includes a vast number of extra features, including:
  • Full control over the appearance and content of emails, which may be totally different for administrators and users
  • Storage of form submissions in database
  • User accounts that you can set up for your clients
  • Simple user interface for searching, viewing, editing, deleting form submissions
  • Optional download of form data in excel spreadsheet or HTML printer-friendly page
  • Multiple languages for the interface (version 1.5.0)
  • And a whole heck of a lot more...!

How to Use

This information is also included in the readme.txt file in the downloadable zipfile.

Configuring your webform:

  1. Download the zipfile and unzip its contents on your computer. Upload the email.php file to somewhere on your server.
  2. Make sure your webpage form tag is sending its information to the emailer script, like so:
    1. <form method="post" action="email.php" />

    (if the email.php file is not located in the same directory, make sure you either include the full URL or relative URL to the file)

  3. Next, include the following two fields (in between the <form> and </form>) tags:
    1. <input type="hidden" name="recipient" value="RECIPIENT_EMAIL_ADDRESS_HERE" />
    2. <input type="hidden" name="redirect_page" value="FULL_REDIRECT_URL_HERE" />
    - The recipient field specifies WHO will receive the email.
    - the redirect_page field specifies where the user will be redirected to after having submitted the form.
    - make sure you include the FULL redirect URL, including "http://", otherwise it may not redirect properly.
  4. Open up the email.php script file in an editor, and find the section entitled "*** USER SETTINGS ***". At the top, you'll see this section:
    1. ################################################################################
    2. // *** USER SETTINGS ***
    3. // this value lets you specify precisely which domains / servers this script will
    4. // process forms for. If your server doesn't provide this information, set
    5. // g_check_sender to false.
    6. $g_check_sender = true;
    7. $g_valid_sites = array("www.site1.com", "www.site2.com", "www.site3.com");
    8. ################################################################################

    This setting lets you specify where the script may receive form information from. This provides basic protection from anyone over the internet using this script to send their emails.

    What you'll need to do is update the "www.yourwebsite.com" value for whatever domain name your form page is located. e.g. if your file is located here: www.thisismydomain.org/dir1/form.html you would add "www.thisismydomain.org". You may add as many domains as you want, provided each one is within double-quotes, and delimited by a comma. e.g.

    1. $valid_sites = array("www.site1.com", "www.site2.com", "www.site3.com");
    Including "http://" is not necessary (nor is the www. part either, actually - but they're all valid).

    However, not all web servers are configured to reveal the sender information to PHP scripts, so if you cannot get it working by adding these values, you may have to deactivate the feature by setting the $g_check_sender value to false.

Special Form Fields

Here is a list of all "special" form fields, and what they mean.

REQUIRED recipient the email address of the recipient
redirect_page where the user is redirected to after form submission
OPTIONAL email_subject allows you to specify the email subject line. This field allows you to specify placeholders, to include values that the person submitting the form has included (see the email_template section below for more information about placeholders).
cc carbon copy: sends an email to this person IN ADDITION to the recipient. For multiple cc's, use cc1, cc2, cc3 ... but be sure to include the initial "cc" field first.
bcc blind carbon copy: blind carbon copy: these send emails to additional people, just like the "cc" fields, but they're names won't appear in the "Sent to" field. Like "cc", you can include multiple bcc fields with "bcc1", "bcc2", etc.
email_from specifies WHO sent the email
reply_to determines the "reply to" email address for each email sent
email_template This optional field allows you to define the location of a text file containing the content of the email to be sent. This file may contain placeholders of the form %fieldname% which, when sent, are replaced with the content of that form field. For an example of how to use email templates, take a look at example2.html and the corresponding email_template.txt file in the downloadable zipfile. Note that:
  • Placeholders are case sensitive and should be identical to the name attribute of the form field.
  • If your name attribute contains spaces, the placeholder should have underscores instead, for example:
    1. <input type="text" name="My text field" value="" />
    would have a placeholder of:
    1. %My_text_field%
receipt_email_field If you wish to send a receipt email to the person submitting the form, you must include this field. This field should have the name of the form field which stores the person's email address. If it is not defined, they will not receive an email.
receipt_email_subject The subject heading of the receipt email. May contain placeholders.
receipt_template This field is required for receipt emails. Like the email_template above, this field should contain the location of a text file containing the content of the receipt email to be sent. As before, this field may contain placeholders.

Example use of optional fields:

  1. <input type="hidden" name="cc" value="[email protected]" />
  2. <input type="hidden" name="cc1" value="[email protected]" />

All other form fields will have their information submitted along with the email.

If the information being sent to the email script isn't in the correct form, it will issue an error message explaining how to fix the problem. Hopefully they're quite clear, so you won't have much difficulty getting it up and running quickly and easily!

Other Notes

*** If you're not using the email template option, any underscores in the name attributes of the input fields will be converted to spaces in the emails sent. PHP does this automatically to make them accessible as valid variable names.

If you have any questions or comments, or come across a bug, please send me a note here.