<?php
/*
Form to Mail (Light) script by AdvanceByDesign.
// Copyright 2009, Robert Rook
// Released under the terms of the
// ABD Free Source Code Licence.
*/
// Find current folder / webserver
$local = "http://".$_SERVER['SERVER_NAME'];
$tmp = explode("/",$_SERVER['PHP_SELF']);
unset($tmp[(count($tmp)-1)]);
$tmp = join("/",$tmp);
$local.= "{$tmp}";
/* ----- BEGIN CONFIGURATION VARIABLES ----- */
$config = array();
$config['to'] = "hide@address.com";
$config['subject'] = "ABD FormMail [_DATE_]"; // You can use _DATE_ and _TIME_
$config['from'] = "hide@address.com";
$config['site'] = "Your site name";
// Page visitor is sent to when message
// has been sent successfully:
$config['page_ok'] = "{$local}/thankyou.php";
/* ----- END CONFIGURATION VARIABLES ----- */
if(isset($_POST['email']) && isset($_POST['name']) && isset($_POST['comments'])) {
$err = "";
// Check the email address is OK
$match = '^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{2,})+$';
if(!eregi($match, $_POST['email'])) {
$err.= "<li>Please provide a valid email address.</li>\n";
}
// Check the name and comments
$_POST['name'] = trim($_POST['name']);
$_POST['comments'] = trim($_POST['comments']);
if(strlen($_POST['name'])<2) {
$err.= "<li>Please provide a name.</li>\n";
}
if(strlen($_POST['comments'])<5) {
$err.= "<li>Please provide a message if you wish to contact us.</li>\n";
}
if(!strlen($err)) {
// Update the subject
$config['subject'] = str_replace("_DATE_", date('d/m/y'), $config['subject']);
$config['subject'] = str_replace("_TIME_", date('h/i/sa'), $config['subject']);
// Replace possible starting HTML tags
$_POST['comments'] = ereg_replace("<","<",$_POST['comments']);
// Create the mail body
$content = "Posted via the Form to Mail script at\n";
$content.= "{$config['site']}\n";
$content.= "------------------------\n";
$content.= "Name: \t{$_POST['name']}\n";
$content.= "Email address:\t{$_POST['email']}\n";
$content.= "Recieved: \t".date('d/m/Y h:i:sa')."\n\n";
$content.= "Message:\n------------------------\n";
$content.= "{$_POST['comments']}\n";
// Check the content of the mail for dangerous
// strings, ie; MIME encoding.
$replace_from = array("content-type:", "mime-version:", "multipart/mixed",
"content-transfer-encoding:", "to:", "bcc:", "cc:");
$replace_to = array("content-type;", "mime-version;", "multipart ./ mixed",
"content-transfer-encoding;", "to;", "bcc;", "cc;");
$content = str_ireplace($replace_from,$replace_to,$content);
// Wrap and send the mail
$content = wordwrap($content,70,"\n",true);
mail($config['to'],$config['subject'],$content,"From: {$config['from']}\r\nReply-To: {$_POST['email']}");
header("Location: {$config['page_ok']}");
die();
}
}
?>