//
//—————————————————————//
// If you want to specify a custom thank you //
// //
//—————————————————————//
// If you want to specify a custom subject //
// //
//—————————————————————//
// You of course need to declare the recipient //
// //
//—————————————————————//
// Choose what email method you want to use //
// //
//—————————————————————//
*/
// Allowed list of Hosts

$valid_hosts = array(‘www.massconline.com’, ‘massconline.com’, ‘netsolhost.com’);

// Allowed list of Recipients

$valid_recipients = array(“uniquesbynj@cox.net”);

error_reporting(E_ALL);

// Security Time. Lets get so only our domains and emails can actually make use of this.

// Where the form is coming from
$refer = $HTTP_SERVER_VARS

[‘HTTP_REFERER’];

function check_referer($refer)
{
global $valid_hosts;

if(!is_array($valid_hosts))
return true;

if($refer == ”)
{
return false;
}
else
{
$temp = explode(‘/’, $refer);

if(in_array($temp[2], $valid_hosts))
{
return true;
}
else
{
echo “
Sorry this isn’t allowed to be used from the $temp[2] domain.
“;
die();
}
}
}

check_referer($refer);

// Who the Email is going to
$to = $_POST[‘recipient’];

function check_recipient($email)
{
global $valid_recipients;
$email = explode(‘,’, $email);

if(!is_array($valid_recipients))
return true;

foreach($email as $to)
{
if(!in_array($to, $valid_recipients))
{
echo “$to is not an allowed email address for this Form.\n”;
die();
}
}
return true;
}

check_recipient($to);

// Now past the Security stuff. Lets move to the Fun work !!!!!

// Lets set the page its being submitted from as the DEFAULT redirect. Then if the value is in the form go to the form value instead.

if (!isset($_POST[‘redirect’]))
{
$redirect=$HTTP_SERVER_VARS[‘HTTP_REFERER’];
}
else
{
$redirect = $_POST[‘redirect’];
}

// Lets make sure Redirect is a Valid URL

$url = $redirect;
$file = @file ($url);
if ($file)
{
$validurl = 1;
}
else
{
// Lets do nothing so the validurl field is still blank.
}

if (!isset($validurl))
{
$siteredirect=$HTTP_SERVER_VARS[‘HTTP_REFERER’];
}
else
{
$siteredirect = $_POST[‘redirect’];
}

// Now that we know its a valid url. Lets find out if there’s a subject set.

if (!isset($_POST[‘subject’]))
{
$subject=”Website Submission from $refer”;
}
else
{
$subject = $_POST[‘subject’];
}

// Date and Time that the Form was Submitted
$date = date(‘m/d/y’);
$time = date(‘G:i’);

if (!isset($_POST[‘sendmailtype’]))
{
$sendmailtype=”mail”;
}
else
{
$sendmailtype = $_POST[‘sendmailtype’];
}

// Regular PHP Mail Function
if ($sendmailtype == “mail”)
{

$to=$_POST[‘recipient’];

// Setting up the Headers for the Email
$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1′ . “\r\n”;

// Special Headers for Mail()
$from = $_POST[’email’];
$frompath = “From: $from”;
$headers .= $frompath . “\r\n”;

// The Body of the Email
$s_message =”

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Start of Automatically Sent Email
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

“;
$s_message .= “~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This email was submitted on $date at $time.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
“;

Foreach (array_keys($_POST) as $key)
{
if (($key == “redirect”) || ($key == “recipient”) || ($key == “subject”))
{
$s_message .=”\n”;
}
else
{
$s_message .= “” . $key . ” : ” . $_POST[$key] . “
“;
}
}

// Browser Type
$useragent= $HTTP_SERVER_VARS[‘HTTP_USER_AGENT’];

// Ip Address
$ipaddress = $HTTP_SERVER_VARS[‘REMOTE_ADDR’];

// Lets add it to the email
$s_message .=”

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Information on your client
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
“;
$s_message .=”Ip Address: $ipaddress
\n”;
$s_message .=”Browser Type: $useragent
\n”;
$s_message .=”Submitted From: $refer
\n”;
$s_message .=”

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
End of Automatically Sent Email
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

“;

// Send the Email
mail($to, $subject, $s_message, $headers);
}

// SMTP Through PHP Function
if ($sendmailtype == “smtp”)
{
include(‘Mail.php’);

// Who the Email is going to
$to=$_POST[‘recipient’];

// Who the Email is coming From
$from = $_POST[’email’];

// The Body of the Email
$s_message =”\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nStart of Automatically Sent Email\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n”;
$s_message .= “\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nThis email was submitted on $date at $time.\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n”;

Foreach (array_keys($_POST) as $key)
{
if (($key == “redirect”) || ($key == “recipient”) || ($key == “subject”))
{
$s_message .=””;
}
else
{
$s_message .= “” . $key . ” : ” . $_POST[$key] . “\n”;
}
}

// Browser Type
$useragent= $HTTP_SERVER_VARS[‘HTTP_USER_AGENT’];

// Ip Address
$ipaddress = $HTTP_SERVER_VARS[‘REMOTE_ADDR’];

// Lets add it to the email
$s_message .=”\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nInformation on your client\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n”;
$s_message .=”Ip Address: $ipaddress\n”;
$s_message .=”Browser Type: $useragent\n”;
$s_message .=”Submitted From: $refer\n”;
$s_message .=”\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\nEnd of Automatically Sent Email\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n”;

// Send the Email
$headers[‘From’] = $from;
$headers[‘To’] = $to;
$headers[‘Subject’] = $subject;
$body = $s_message;
$mail_object =& Mail::factory(“smtp”);
$mail_object->send($to, $headers, $body);
}

// Redirection to the Thank you Page
$url=”Location: $siteredirect”;
header($url);
?>