set('captcha', $captcha);
if (($action = $_GET['action'] ?? '') == 'send') {
// this flag field (faked the name as 'subject')is hidden, so normal user
// won't be able to fill it out. this is to protect against bots
if (empty($_POST['subject'])) {
$send_info = Validations::randomizedInputNames($_POST);
if (isset($captcha) && $captcha instanceof Captcha) {
if (isset($send_info['email5ck1'])) {
$send_info['email'] = $send_info['email5ck1'];
}
// now we have a captcha image, let's check that first.
if (!$captcha->isHuman(
($resp = $_POST['g-recaptcha-response'] ?? '') ?: ($_POST['recaptcha_response_field'] ?? ''),
$_POST['recaptcha_challenge_field'] ?? ''
)
) {
//if the user fails the captcha
$_SESSION['send_info'] = $send_info;
$_SESSION['security_code_error_msg'] = $captcha->error();
$messageStack->addSession(
'comment',
"Your reCAPTCHA™ input was incorrect. Please try again."
);
$error = true;
} else {
//the user passed the captcha
unset($_SESSION['security_code']);
}
}
if (isset($send_info['name'])
&& isset($send_info['phone'])
&& isset($send_info['email'])
&& isset($send_info['enquiry'])
) {
$name = trim(sanitizeString(stripslashes($send_info['name'])));
$phone = trim(sanitizeString(stripslashes($send_info['phone'])));
$email_address = trim(sanitizeString(stripslashes($send_info['email'])));
$enquiry = trim(stripslashes(sanitizeString($send_info['enquiry'])));
if (!Validations::email($email_address)) {
$error = true;
$messageStack->addSession('comment', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
}
if (!($phone = Validations::phoneNumber($phone))) {
$error = true;
$messageStack->addSession('comment', 'Phone number is potentially invalid. Please retype it.');
}
if (!$error) {
$enquiry = "Phone: " . $phone . "\nComments:\n" . $enquiry;
if (isset($send_info['studio_location']) && ($studio = trim($send_info['studio_location']))) {
$enquiry .= "\nStudio Location: {$studio}";
}
if (($customer_id = (int) ($_SESSION['customer_id'] ?? 0)) > 0) {
$enquiry .= "\nUser profile page: " . HTTPS_SERVER . DIR_WS_CATALOG
. "admin/customers.php?selected_box=customers&cID="
. $customer_id . "";
}
$recipient = STORE_OWNER;
$recipientEmail = CONTACT_US_EMAIL_ADDRESS;
$headers = [];
if (CLIENT_CODE == Client::ELLIOTT) {
$recipient = 'Elliott Corporate';
$recipientEmail = 'corpcomm@elliott-turbo.com';
$headers[] = 'Bcc: ' . CONTACT_US_EMAIL_ADDRESS;
}
tep_mail(
$recipient,
$recipientEmail,
'Enquiry from ' . STORE_NAME . ' - Contact Us',
str_replace("\n", '
', $enquiry),
$name,
$email_address,
null,
$headers
);
if (isset($send_info['use_ajax']) && $send_info['use_ajax'] == true) {
die(json_encode(true));
}
if (isset($send_info['next_page'])) {
tep_redirect(tep_href_link($send_info['next_page']));
}
tep_redirect(tep_href_link(FILENAME_CONTACT_US, 'action=success'));
} else {
if (isset($send_info['use_ajax']) && $send_info['use_ajax'] == true) {
// A new object retrieves the messages set in $_SESSION that aren't yet in the object
$ajaxMessage = new MessageStack();
die(json_encode($ajaxMessage->output('comment')));
}
// Repopulate information because it failed
$_SESSION['send_info'] = $send_info;
tep_redirect(tep_href_link('contact_us.php'));
}
}
}
} elseif (isset($_SESSION['send_info'])) {
$send_info = $_SESSION['send_info'];
unset($_SESSION['send_info']);
} elseif (($customer_id = (int) ($_SESSION['customer_id'] ?? 0)) > 0) {
$currCustomer = Customer::getObject([$customer_id]);
$send_info['name'] = "{$_SESSION['customer_first_name']} {$_SESSION['customer_last_name']}";
$send_info['phone'] = $currCustomer->getPhone();
$send_info['email'] = $currCustomer->getEmail();
$send_info['enquiry'] = "";
}
$breadcrumb->add('Contact Us', tep_href_link(FILENAME_CONTACT_US));
$template->title = 'Contact Us';
$template->startHTML();
$template->startPage();
if ($action == 'success') {
$template->defaultName = 'contact_us_success';
unset($_SESSION['send_info']);
unset($_SESSION['security_code_error_msg']);
} else {
$template->defaultName = 'contact_us';
}
$template->set('messageStack', $messageStack);
$template->set('send_info', $send_info);
$template->parseTemplate();
$template->endPage();