contact-code.inc
require_once(‘recaptchalib.inc’);
global $errmsg;
global $mailsent;
global $good_captcha;
global $captcha_html;
global $captcha_error;
$errmsg=array();
$mailsent=false;
$good_captcha=false;
$captcha_html=”;
$captcha_error=”;
// code thanks to Google – example-captcha.php
// Get a key from https://www.google.com/recaptcha/admin/create
$publickey = “6LfNf-4SAAAAANFbnWdoHS9ot-X2EhP8CLsAmi–“;
$privatekey = “6LfNf-4SAAAAAMn3JsZt-gQqfdDjA8t1PBTsDfDg”;
# was there a reCAPTCHA response?
if ($_POST[“recaptcha_response_field”]) {
$resp = recaptcha_check_answer ($privatekey,
$_SERVER[“REMOTE_ADDR”],
$_POST[“recaptcha_challenge_field”],
$_POST[“recaptcha_response_field”]);
if ($resp->is_valid) {
$good_captcha = true;
} else {
# set the error code so that we can display it
$good_captcha = false;
$captcha_error = “Please solve the CAPTCHA to submit”; //$resp->error;
}
}
if ($good_captcha) {
$required=array(‘name’,’business’,’email’,’phone’);
$allfields=array(‘name’,’business’,’email’,’phone’,’interests’,’source’);
if (array_key_exists(‘contact_submit’,$_POST)) {
$fld=array();
foreach ($allfields as $val) {
$fld[$val]=array_key_exists(“contact_$val”,$_POST)?trim($_POST[“contact_$val”]):”;
}
foreach ($required as $val) {
if (!$fld[$val]) {
$errmsg[]=ucfirst($val).” is a required field.”;
}
}
$emailpattern=’/^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}$/i’;
if (!preg_match($emailpattern,$fld[’email’])) {
$errmsg[]=”You must provide a valid email address.”;
}
if (!count($errmsg)) {
$textmsg=”A contact request has been submitted from {$_SERVER[‘SCRIPT_NAME’]}. The form information is shown below.nn”;
foreach ($fld as $key=>$val) {
$textmsg.=”{$key}: $valnn”;
}
$headers=array();
$headers[]=”To: danielle.griffin@mercury-group.com,sarah.learnard@mercury-group.com,catherine.lawson@mercury-group.com”;
//$headers[]=”To: steve@poweredbymomentum.com”;
$headers[]=”From: Mercury Group Contact Page
require_once ’email-class.inc’;
$mailitem=new html_mime_mail($headers);
$mailitem->add_html(nl2br($textmsg),$textmsg);
$mailitem->build_message();
$mailitem->send(”,”,”,”,’Web Site Contact Request’);
$mailsent=true;
} else {
$mailsent=false;
}
}
}
$captcha_html = recaptcha_get_html($publickey, $captcha_error);