Here it is :
<?php
####################################################################################
#
Emailer
#
- Supports PHP Versions 4.0 upwards.
- Supports up to 100 posted fields in the format of "01namehere" (2 digit integer
to signify order, plus name of field.)
- Supports storing data to a MySQL Database
#
Requirements
- PHP with working mail() function, using sendmail or equivalent
#
####################################################################################
GENERAL OPTIONS
#
Set email address to send mail
$toemailaddress = "info@cruiseteanau.co.nz";
#
Set name and address email should come from
Example - Your website name, Site Support Request, etc
Custom name toggle - use the persons name/email address, for use with reply button when
receiving email
1 - Use Custom name/email
0 - Use Static name/email
$customname = 1;
Custom name/email settings
Select the POST field used for email sender name and email sender address
$fromnamefield = "name";
$fromemailfield = "email";
Static name/email settings
$fromname = "Cruise Te Anau";
$fromemail = "peter@cruiseteanau.co.nz";
#
Set email subject
$emailsubject = "Enquiry";
#
Set URL to send users to on successful email
$gotourl = "Thankyou.html";
#
Set allowed POST values
EXAMPLE - $allowed = array("01title", "02name", "03phone", "04fax", "05mobile" , "06email", "07address", "08city", "09comments",);
$allowed = array("name", "email", "phone", "fax", "address", "query",);
######### BASIC EMAILER FORM STOP HERE ###########
MYSQL DATABASE OPTIONS
Note - Database Table must be setup with each allowed POST field in order as its name
Example:-
POST Field - "01name"
Database Column - name
Columns should be named lower case within the database
#
Store data in MySQL? (0 or 1)
$mysqlstore = 0;
Database Details
$dbhost - Database Server Hostname/IP
$dbuser - MySQL Username
$dbpass - MySQL Password
$dbname - Database Name on MySQL Server
$dbtable - Table within Database to store data
$dbhost = "localhost";
$dbuser = "user";
$dbpass = "pass";
$dbname = "name";
$dbtable = "table";
####################################################################################
DO NOT MODIFY BELOW THIS LINE
####################################################################################
function minimum_version($vercheck) {
$minver = explode(".", $vercheck);
$curver = explode(".", phpversion());
if (($curver[0] < $minver[0])
|| (($curver[0] = $minver[0])
&& ($curver[1] < $minver[1]))
|| (($curver[0] = $minver[0])
&& ($curver[1] = $minver[1])
&& ($curver[2][0] < $minver[2][0]))) {
return false;
} else {
return true;
}
}
if (!minimum_version("4.1.0")) {
$emailvars = $HTTP_POST_VARS;
} else {
$emailvars = $_POST;
}
$varstosend = array();
ksort($emailvars);
$maxkeylen = 0;
foreach ($emailvars as $name => $value) {
$check = in_array($name, $allowed);
if ($check) {
$name2 = substr($name, 2);
if (strlen($name2) > $maxkeylen) {
$maxkeylen = strlen($name2);
}
$namestart = strtoupper(substr($name2, 0, 1));
$namerest = substr($name2, 1);
$newname = $namestart.$namerest;
$varstosend[$newname] = $value;
}
}
if ($mysqlstore == 1) {
$dbc = mysql_connect($dbhost, $dbuser, $dbpass);
$dbs = mysql_select_db($dbname, $dbc);
foreach ($varstosend as $key => $value) {
$insertcol .= strtolower($key).", ";
$insertcoldata .= "\'".$value."\', ";
}
$insertcol = substr($insertcol, 0, -2);
$insertcoldata = stripslashes(substr($insertcoldata, 0, -2));
$dbinsquery = "INSERT INTO ".$dbtable." (".$insertcol.") VALUES (".$insertcoldata.")";
$dbins = mysql_query($dbinsquery);
if (!$dbins) {
$error = 1;
$dberror = 1;
$dberrordesc = mysql_error();
}
}
foreach ($varstosend as $key => $val) {
$emailmessage .= $key;
for ($i = strlen($key); $i < $maxkeylen; $i++) {
$emailmessage .= " ";
}
$emailmessage .= " - ".$val."\n";
}
if ($customname == 0) {
$fromemailname = $fromname;
$fromemailaddress = $fromemail;
} elseif ($customname == 1) {
$fromemailname = $emailvars[$fromnamefield];
$fromemailaddress = $emailvars[$fromemailfield];
}
$sendmail = mail($toemailaddress, $emailsubject, $emailmessage, "From: ".$fromemailname." <".$fromemailaddress.">\r\n");
if (!$sendmail) {
$error = 1;
$mailerror = 1;
}
if ($error == 1) {
echo "<title>Emailer Error</title>";
if ($dberror == 1) {
echo "<center><b>Error</b> - Cannot add to database.</center>";
echo "<center>".$dberrordesc."</center>";
} if ($mailerror == 1) {
echo "<center><b>Error</b> - Cannot send mail.</center>";
}
} else {
$headerlocation = "Location: ".$gotourl;
header($headerlocation);
}
?>
Here is the mail:
Dress - 251 Talbot St
Ail - spud@dropzone.com
X -
Me - Kevin Bedford
One - 910-947-1875
Ery - Booking water shuttle to Brod Bay
Saturday Feb.4
2 adults