-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontact.php
43 lines (33 loc) · 1.42 KB
/
contact.php
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
<?php require_once 'src/TemplateRenderer.class.php';
$success = null;
if(isset($_POST['submit'])) {
require_once('src/recaptcha/src/autoload.php');
require_once('php/localCredentials.php');
// Google recaptcha site key and secret key
$siteKey = '6LdLHAsTAAAAAMpMPpkmgNh4FDNEl7WJV_3lNuqH';
$secret = $recaptchaSecret;
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
$resp = $recaptcha->verify(filter_var($_POST['g-recaptcha-response'], FILTER_SANITIZE_STRING));
// set $success to fail by default on form submission
$success = 'fail';
if ($resp->isSuccess()) {
$name = filter_var($_POST['contact_name'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['contact_email'], FILTER_SANITIZE_EMAIL);
$reason = filter_var($_POST['contact_reason'], FILTER_SANITIZE_STRING);
$message = filter_var($_POST['contact_message'], FILTER_SANITIZE_STRING);
$to = "[email protected]";
$subject = "Digital Austin Collection: " . $reason;
$body = $message . "\n\n" . "From: " . $name . " - " . $email;
if (mail($to, $subject, $body)) {
$success = 'success';
}
} else {
$errors = $resp->getErrorCodes();
}
}
$template = new TemplateRenderer();
// Include any variables as an array in the second param
print $template->render('contact.html.twig', array(
'success' => $success,
'body_id' => 'contact'
));