-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathajax-contact.php
More file actions
47 lines (36 loc) · 1.66 KB
/
ajax-contact.php
File metadata and controls
47 lines (36 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
include($_SERVER['DOCUMENT_ROOT'] . "/includes/inc-db-connection.php");
include($_SERVER['DOCUMENT_ROOT'] . "/includes/inc-functions.php");
if (isset($_POST['contact_name'])) {
if (empty($_POST['contact_name']) || empty($_POST['contact_subject']) || empty($_POST['contact_email']) || empty($_POST['contact_message'])) {
stdErr("Please fill in <strong>all</strong> fields.");
} else {
$recaptcha_secret_key = getValue("recaptcha2_secret_key");
$recaptcha_response = $_POST['g-recaptcha-response'];
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha_data = array(
'secret' => $recaptcha_secret_key,
'response' => $recaptcha_response,
'remoteip' => $_SERVER['REMOTE_ADDR']
);
$recaptcha_options = array(
'http' => array(
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($recaptcha_data)
)
);
$recaptcha_context = stream_context_create($recaptcha_options);
$recaptcha_result = file_get_contents($recaptcha_url, false, $recaptcha_context);
$recaptcha_response_data = json_decode($recaptcha_result);
if ($recaptcha_response_data->success) {
stdMsg("Thank you <strong>{$_POST['contact_name']}</strong>, we will be in touch soon!");
sendEmail(getValue("site_admin_email"), $_POST['contact_email'], $_POST['contact_subject'], $_POST['contact_message']);
} else {
stdErr("reCAPTCHA verification failed. Please try again.");
}
}
}
}
?>