$FM_VERS = "8.22"; // script version
/* ex:set ts=4 sw=4 et:
* FormMail PHP script from Tectite.com. This script requires PHP 4 or later.
* Copyright (c) 2001-2010 Root Software and Open Concepts (Vic) Pty Ltd
* (ABN 12 130 429 248), Melbourne, Australia.
* This script is free for all use as described in the "Copying and Use" and
* "Warranty and Disclaimer" sections below.
* Visit us at http://www.tectite.com/ for updates and more information.
*** If you use Tectite FormMail, please support its development and other
*** freeware products by putting the following link on your website:
*** Visit www.tectite.com for free <a href="http://www.tectite.com/">FormMail</a>.
* Author: Russell Robinson, 2nd October 2001
* Read This First
* This script is very well documented and quite large! It looks daunting,
* but really isn't.
* If you have experience with PHP or other scripting languages,
* here's what you *need* to read:
* - Configuration (TARGET_EMAIL & DEF_ALERT)
* - Creating Forms
* That's it! (Alternatively, just read the Quick Start and/or
* Quicker Start section below).
* Full configuration documentation is here:
* NOTE: do not read or modify this script or any PHP script
* with DreamWeaver or FrontPage!
* Many versions of those programs silently corrupt PHP scripts.
* To accept information from an HTML form via HTTP and mail it to recipients.
* What does this PHP script do?
* On your web site, you may have one or more HTML forms that accept
* information from people visiting your website. Your aim is for your
* website to email that information to you and/or add it to a database.
* FormMail performs those functions.
* Quick Start
* 1. Edit this file and set TARGET_EMAIL for your requirements (near
* line 256 in this file - replace "yourhost\.com" with your mail server's
* name). We also strongly recommend you set DEF_ALERT (the next
* configuration below TARGET_EMAIL).
* 2. Install this file as formmail.php (or other name ending in .php)
* on your web server.
* Test alerts by using your browser to open a URL to the script:
* Alerts are the only way FormMail can tell you the details of
* errors or faults.
* 3. Create an HTML form and:
* - specify a hidden field called "recipients" with the email address
* of the person to receive the form's results.
* - in the your form tag set the action attribute to
* the formmail.php you uploaded to your web server
* Once you have FormMail working, you may be interested in some advanced
* usage and features. We have HOW-TO guides at www.tectite.com which
* describe many of the advanced processing you can do with FormMail.
* Quicker Start
* Use the FormMail Configuration Wizard here:
* By answering a few questions you'll get a configured FormMail and
* a sample HTML form ready to upload and use on your server.
* For a list of features go to: http://www.tectite.com/formmailpage.php
* Security is the primary concern in accepting data from your website
* Tectite FormMail has several security features designed into it. Note,
* however, it requires configuration for your particular web site.
* To configure this script, go to the section titled "CONFIGURATION"
* (after reading the legal stuff below).
* There is only one mandatory setting: TARGET_EMAIL
* and one strongly recommended setting: DEF_ALERT
* Full configuration information is available here:
* Creating Forms
* Go to this URL to learn how to write HTML forms for use with
* Tectite FormMail: http://www.tectite.com/fmdoc/creating_forms.php
* Copying and Use (Software License)
* Tectite FormMail is provided free of charge and may be freely distributed
* and used provided that you:
* 1. keep this header, including copyright and comments,
* in place and unmodified; and,
* 2. do not charge a fee for distributing it, without an agreement
* in writing with Root Software allowing you to do so; and,
* 3. if you modify FormMail before distributing it, you clearly
* a) who you are
* b) how to contact you
* c) what changes you have made
* d) why you have made those changes.
* By using any of our products, including this script, you are
* agreeing to our standard Terms and Conditions, available here:
* This is free software and the Software License shown above
* is to be read in conjunction with our standard Terms and Conditions.
* Warranty and Disclaimer
* Tectite FormMail is provided free-of-charge and with ABSOLUTELY NO WARRANTY.
* It has not been verified for use in critical applications, including,
* but not limited to, medicine, defense, aircraft, space exploration,
* or any other potentially dangerous activity.
* By using Tectite FormMail you agree to indemnify Root Software and
* Open Concepts (Vic) Pty Ltd, their agents, employees, directors and
* associated companies and businesses from any liability whatsoever.
* We still care
* If you find a bug or fault in FormMail, please report it to us.
* We will respond to your report and make endeavours to rectify any
* faults you've detected as soon as possible.
* To contact us please register on our forums at:
* or view our contact information:
* Version History
* Near the top of this file, you'll find its version. The version
* line looks like this:
* $FM_VERS = "N.MM"; /* script version ...
* The version history used to be located within this file. However,
* starting with Version 8.00 we've moved it...
* You can read the complete version history of FormMail on our
* main website here:
// Capture the current date and time, for various purposes.
$lNow = time();
ini_set('track_errors',1); // enable $php_errormsg
$aAlertInfo = array();
$aPHPVERSION = array();
$sLangID = ""; // the language ID
$aMessages = array(); // all FormMail messages in the appropriate
$bUseOldVars = IsOldVersion($aPHPVERSION);
// disable this silly setting (usually not enabled)
// it's also deprecated from PHP version 5.3.0
// seed the random number generate if not version 4.2.0 or later
// we set references to the appropriate arrays to handle PHP version differences
// Session vars are selected after we start the session.
$aServerVars = &$HTTP_SERVER_VARS;
$aGetVars = &$HTTP_GET_VARS;
$aFormVars = &$HTTP_POST_VARS;
$aFileVars = &$HTTP_POST_FILES;
$aEnvVars = &$HTTP_ENV_VARS;
$aServerVars = &$_SERVER;
$aGetVars = &$_GET;
$aFormVars = &$_POST;
$aFileVars = &$_FILES;
$aEnvVars = &$_ENV;
$bIsGetMethod = false;
// If the form submission was using the GET method, switch to the
// GET vars instead of the POST vars
if (isset($aServerVars["REQUEST_METHOD"]) && $aServerVars["REQUEST_METHOD"] === "GET")
$bIsGetMethod = true;
$aFormVars = &$HTTP_GET_VARS;
$aFormVars = &$_GET;
$SCHEME = ($aServerVars['SERVER_PORT'] == 80) ? "http://" : "https://";
$SCHEME = "";
if (isset($aServerVars['SERVER_NAME']) && $aServerVars['SERVER_NAME'] !== "")
$SERVER = $aServerVars['SERVER_NAME'];
elseif (isset($aServerVars['SERVER_ADDR']) && $aServerVars['SERVER_ADDR'] !== "")
$SERVER = $aServerVars['SERVER_ADDR'];
$SERVER = "";
/* CONFIGURATION (do not alter this line in any way!!!) */
* This is the *only* place where you need to modify things to use formmail.php
* on your particular system. This section finishes at "END OF CONFIGURATION".
* Help for all settings can be found on our website:
* Also, above each setting is a direct URL to the help information for the
/* Help: http://www.tectite.com/fmdoc/email_name.php */
define("EMAIL_NAME","^[-a-z0-9.]+"); // the '^' is an important security feature!
/* Help: http://www.tectite.com/fmdoc/target_email.php */
$TARGET_EMAIL = array(EMAIL_NAME."@mywebsite\.com$");
/* Help: http://www.tectite.com/fmdoc/def_alert.php */
/* Help: http://www.tectite.com/fmdoc/set_real_document_root.php */
$SET_REAL_DOCUMENT_ROOT = ""; // overrides the value set by SetRealDocumentRoot function
// override $REAL_DOCUMENT_ROOT from the $SET_REAL_DOCUMENT_ROOT value (if any)
// Do not alter the following code (next 3 lines)!
if (isset($SET_REAL_DOCUMENT_ROOT) && $SET_REAL_DOCUMENT_ROOT !== "")
$REAL_DOCUMENT_ROOT = $SET_REAL_DOCUMENT_ROOT;
/* Help: http://www.tectite.com/fmdoc/config_check.php */
$CONFIG_CHECK = array("TARGET_EMAIL");
/* Help: http://www.tectite.com/fmdoc/at_mangle.php */
/* Help: http://www.tectite.com/fmdoc/target_urls.php */
$TARGET_URLS = array(); // default; no URLs allowed
/* Help: http://www.tectite.com/fmdoc/head_crlf.php */
/* Help: http://www.tectite.com/fmdoc/body_lf.php */
define("BODY_LF","\r\n"); // the new default: use this for CR+LF
//define("BODY_LF","\n"); // the old default: just LF
/* Help: http://www.tectite.com/fmdoc/from_user.php */
$FROM_USER = ""; // the default - setting not used
/* Help: http://www.tectite.com/fmdoc/sendmail_f_option.php */
define("SENDMAIL_F_OPTION_LINE",__LINE__-1); // don't modify this line!
/* Help: http://www.tectite.com/fmdoc/fixed_sender.php */
$FIXED_SENDER = "";
/* Help: http://www.tectite.com/fmdoc/set_sender_from_email.php */
/* Help: http://www.tectite.com/fmdoc/ini_set_from.php */
/* Help: http://www.tectite.com/fmdoc/logdir.php */
$LOGDIR = ""; // directory for log files; empty string to
// disallow log files
/* Help: http://www.tectite.com/fmdoc/autorespondlog.php */
$AUTORESPONDLOG = ""; // file name in $LOGDIR for the auto responder
// log; empty string for no auto responder log
/* Help: http://www.tectite.com/fmdoc/csv_file_settings.php */
$CSVDIR = ""; // directory for csv files; empty string to
// disallow csv files
$CSVSEP = ","; // comma separator between fields (columns)
$CSVINTSEP = ";"; // semicolon is the separator for fields (columns)
// with multiple values (checkboxes, etc.)
$CSVQUOTE = '"'; // all fields in the CSV are quoted with this character;
// default is double quote. You can change it to
// single quote or leave it empty for no quotes.
//$CSVQUOTE = "'"; // use this if you want single quotes
$CSVOPEN = ""; // set to "b" to force line terminations to be
// kept as $CSVLINE setting below, regardless of
// operating system. Keep as empty string and
// leave $CSVLINE unchanged, to get text file
// terminations for your server's operating system.
// (Line feed on UNIX, carriage-return line feed on Windows).
$CSVLINE = "\n"; // line termination for CSV files. The default is
// a single line feed, which may be modified for your
// server's operating system. If you want to change
// this value, you *must* set $CSVOPEN = "b".
[...whole lot more code here...]
Thanks for any help on this, much appreciated.
<form method="post" action="http://www.mywebsite.com/path/formmail.php" name="SampleForm">
<input type="hidden" name="env_report" value="REMOTE_HOST,REMOTE_ADDR,HTTP_USER_AGENT,AUTH_TYPE,REMOTE_USER">
<input type="hidden" name="recipients" value="firstname.lastname@example.org" />
<input type="hidden" name="subject" value="Subject line" />
<table width="100%" border="0" id="form-container" cellpadding="0" cellspacing="0">
<td valign="top" class="label-container"><label>Name:</label></td>
<td class="field-container"><input type="text" name="realname" class="field" id="Name" /></td>
<td valign="top" class="label-container"><label>Email Address:</label></td>
<td class="field-container"><input type="text" name="email" class="field" id="Email" /></td>
<td valign="top" class="label-container"><label>Phone:</label></td>
<td class="field-container"><input type="text" name="phone" class="field" id="Phone" /></td>
<input type="submit" class="btn" name="submit" value="SUBMIT" />