From: vincent@cubedesigners.com Date: Tue, 24 Nov 2020 17:08:47 +0000 (+0000) Subject: #4016 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=504907114e948571213e9cf882023e005412e013;p=cubeextranet.git #4016 --- diff --git a/fluidbook/mailer/index.php b/fluidbook/mailer/index.php index 4d35fc776..0cf68fceb 100644 --- a/fluidbook/mailer/index.php +++ b/fluidbook/mailer/index.php @@ -26,6 +26,7 @@ function process() return $result; } + // Check that important fields are present if (empty($_POST['_formID']) || empty($_POST['_recipient']) || empty($_POST['_verification'])) { $result['message'] = 'Error: missing form configuration data'; @@ -40,6 +41,29 @@ function process() return $result; } + // Check captcha if enabled + $recaptcha = ['toysrus-2020' => '6LfXYeEZAAAAABhZuPNOCTYgcW5svieZKPYBrOYb']; + if (isset($recaptcha[$_POST['_formID']])) { + $url = 'https://www.google.com/recaptcha/api/siteverify'; + $data = array( + 'secret' => $recaptcha[$_POST['_formID']], + 'response' => $_POST["g-recaptcha-response"] + ); + $options = array( + 'http' => array( + 'method' => 'POST', + 'content' => http_build_query($data) + ) + ); + $context = stream_context_create($options); + $verify = file_get_contents($url, false, $context); + $captcha_success = json_decode($verify); + if ($captcha_success->success === false) { + $result['message'] = 'Error: catcha failed'; + return $result; + } + } + // If we get to here, the form can be processed and the email sent. // First, build the email body $content = buildEmail($_POST); @@ -108,6 +132,10 @@ function buildEmail($data) 'organization' => ['fr' => 'Organization', 'en' => 'Organization'], 'best_time_to_contact' => ['fr' => 'Heure de contact préférée', 'en' => 'Best time to contact'], 'more_info' => ['fr' => 'Plus d\'information', 'en' => 'More info'], + 'product_1' => ['fr' => 'Produit 1', 'en' => 'Product 1'], + 'product_2' => ['fr' => 'Produit 2', 'en' => 'Product 2'], + 'product_3' => ['fr' => 'Produit 3', 'en' => 'Product 3'], + 'subscribe' => ['fr' => 'Inscription', 'en' => 'Subscribe'], ]; $locale = $data['_locale'] ?? 'en';