"", "labelcolor"=>"black", "label"=>"Name", "sublabelcolor"=>"gray", "sublabel"=>"Enter your name");
$email = array("data"=>"", "labelcolor"=>"black", "label"=>"Email Address", "sublabelcolor"=>"gray", "sublabel"=>"mailbox@yourdomain.com");
$phone = array("data"=>"", "labelcolor"=>"black", "label"=>"Phone Number", "sublabelcolor"=>"gray", "sublabel"=>"As in (999)999-9999 x9999");
$subject = array("data"=>"", "labelcolor"=>"black", "label"=>"Subject", "sublabelcolor"=>"gray", "sublabel"=>"Enter a simple topic");
$message = array("data"=>"", "labelcolor"=>"black", "label"=>"Message", "sublabelcolor"=>"gray", "sublabel"=>"Enter your message here");
if (array_key_exists("_submit_check",$_POST)) {
// Sanitize the input
// if (filter_has_var(INPUT_POST, "name"))
// $name["data"] = mysql_escape_string(filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING));
// if (filter_has_var(INPUT_POST, "email"))
// $email["data"] = filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL);
// if (filter_has_var(INPUT_POST, "phone"))
// $phone["data"] = mysql_escape_string(filter_input(INPUT_POST, "phone", FILTER_SANITIZE_STRING));;
// if (filter_has_var(INPUT_POST, "subject"))
// $subject["data"] = mysql_escape_string(filter_input(INPUT_POST, "subject", FILTER_SANITIZE_STRING));;
// if (filter_has_var(INPUT_POST, "message"))
// $message["data"] = mysql_escape_string(filter_input(INPUT_POST, "message", FILTER_SANITIZE_STRING));
if (filter_has_var(INPUT_POST, "name"))
$name["data"] = filter_input(INPUT_POST, "name", FILTER_SANITIZE_STRING);
if (filter_has_var(INPUT_POST, "email"))
$email["data"] = filter_input(INPUT_POST, "email", FILTER_SANITIZE_EMAIL);
if (filter_has_var(INPUT_POST, "phone"))
$phone["data"] = filter_input(INPUT_POST, "phone", FILTER_SANITIZE_STRING);
if (filter_has_var(INPUT_POST, "subject"))
$subject["data"] = filter_input(INPUT_POST, "subject", FILTER_SANITIZE_STRING);
if (filter_has_var(INPUT_POST, "message"))
$message["data"] = filter_input(INPUT_POST, "message", FILTER_SANITIZE_STRING);
// Validate the input
$errorColor = "red";
$formError = false;
if (trim($name["data"]) == "") {
$name["label"] = "Missing Name";
$name["labelcolor"] = $errorColor;
$name["sublabel"] = "What is your name?";
$name["sublabelcolor"] = $errorColor;
$formError = true;
}
if (trim($email["data"]) == "") {
$email["label"] = "Missing Email Address";
$email["labelcolor"] = $errorColor;
$email["sublabel"] = "What is your Email address?";
$email["sublabelcolor"] = $errorColor;
$formError = true;
}
elseif (!filter_var($email["data"], FILTER_VALIDATE_EMAIL)) {
$email["label"] = "Invalid Email Address";
$email["labelcolor"] = $errorColor;
$email["sublabel"] = "What you entered won't work";
$email["sublabelcolor"] = $errorColor;
$formError = true;
}
if (trim($phone["data"]) == "") {
$phone["label"] = "Missing Phone Number";
$phone["labelcolor"] = $errorColor;
$phone["sublabel"] = "What is your phone number?";
$phone["sublabelcolor"] = $errorColor;
$formError = true;
}
$pattern = '/^(?:1(?:[. -])?)?(?:\((?=\d{3}\)))?([2-9]\d{2})'
.'(?:(?<=\(\d{3})\))? ?(?:(?<=\d{3})[.-])?([2-9]\d{2})'
.'[. -]?(\d{4})(?: (?i:x)\.? ?(\d{1,5}))?$/';
if (!preg_match($pattern, $phone["data"])) {
$phone["label"] = "Invalid Phone Number";
$phone["labelcolor"] = $errorColor;
$phone["sublabel"] = "Format as (999)999-9999 x9999";
$phone["sublabelcolor"] = $errorColor;
$formError = true;
}
if (trim($subject["data"]) == "") {
$subject["label"] = "Missing Subject";
$subject["labelcolor"] = $errorColor;
$subject["sublabel"] = "What is your message topic?";
$subject["sublabelcolor"] = $errorColor;
$formError = true;
}
if (trim($message["data"]) == "") {
$message["label"] = "Missing Message";
$message["labelcolor"] = $errorColor;
$message["sublabel"] = "What do you want to say to us?";
$message["sublabelcolor"] = $errorColor;
$formError = true;
}
if ($formError) {
$pageMessage = "
It appears there are some issues with the information you entered in the form. " .
"Please check the information you entered and try again." . $rn;
$formHTML = makeForm();
}
else {
// send the email message to us
$textareaMessage = $message["data"];
$textareaMessage = stripslashes(str_replace('\r\n', "\n", $textareaMessage));
$mailTo = $mailRecipients;
$mailSubject = $subject["data"];
$mailHeaders = "From: Climax Photo Website " . $rn;
$mailHeaders .= "Reply-To: " . $name["data"] . " <" . $email["data"] . ">" . $rn;
$mailHeaders .= "Bcc: eric@highlandsmedia.com" . $rn;
$mailBody = $name["data"] . " (" . $email["data"] . ", " . $phone["data"] .
") has just sent the following message to Climax Photo using the Contact page:\n\n" .
html_entity_decode($textareaMessage, ENT_QUOTES);
//$mailBody .= hex_dump($message["data"]);
$status = mail($mailTo, $mailSubject, $mailBody, $mailHeaders);
// handle the mail status
$pageMessage = "
";
if ($status)
$pageMessage .= "
Thank you for your message. We will be in touch with you as soon as possible.";
else
$pageMessage .= "
Oops! Something went wrong sending your message. Try clicking the back button on your " .
"browser and attempt to send the message again. If all else fails, please give us a phone call. Thank you.";
$pageMessage .= "
";
}
}
else {
$pageMessage = "
Complete the form below and click Send to contact us by e-mail." . $rn;
$formHTML = makeForm();
}
function hex_dump($data, $newline="\n")
{
static $from = '';
static $to = '';
static $width = 16; # number of bytes per line
static $pad = '.'; # padding for non-visible characters
if ($from==='')
{
for ($i=0; $i<=0xFF; $i++)
{
$from .= chr($i);
$to .= ($i >= 0x20 && $i <= 0x7E) ? chr($i) : $pad;
}
}
$hex = str_split(bin2hex($data), $width*2);
$chars = str_split(strtr($data, $from, $to), $width);
$offset = 0;
$dumpInfo = "\n\nThe following is for debugging purposes:\n\n";
foreach ($hex as $i => $line)
{
$dumpInfo .= sprintf('%6X',$offset).' : '.implode(' ', str_split($line,2)) . ' [' . $chars[$i] . ']' . $newline;
$offset += $width;
}
return $dumpInfo;
}
function makeForm () {
global $name, $email, $phone, $subject, $message;
$formHTML = "
Please Note: We do not have a retail outlet at this location.
We serve internet orders and wholesale only at our warehouse and
manufacturing facility and cannot accept walk-in orders.
Contact Numbers
Our sales staff is available from 8:30 am ET to 5:00 PM ET to answer your phone calls.