This repository has been archived by the owner on Oct 26, 2018. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
contact.php
61 lines (59 loc) · 2.78 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
include './res/header.php';
// Register API keys at https://www.google.com/recaptcha/admin
$siteKey = $config['recaptcha-key'];
$secret = $config['recaptcha-secret'];
// reCAPTCHA supported 40+ languages listed here: https://developers.google.com/recaptcha/docs/language
$lang = "en";
// The response from reCAPTCHA
$resp = null;
// The error code from reCAPTCHA, if any
$error = null;
if (!defined("DEBUG")) $reCaptcha = new ReCaptcha($secret);
// Was there a reCAPTCHA response?
if (isset($_POST["g-recaptcha-response"]) && $_POST["g-recaptcha-response"]) {
$resp = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]
);
}
$output = null;
if (isset($_POST['post'])) {
if ($resp != null && $resp->success) {
$sent = true;
$email = $_POST['email'];
$message = $_POST['message'];
$to = $config['email-receiver'];
$subject = "New mail from " . $email;
$message = "Hello,\nYou've recived a new message from: " . $email . "\n\nMessage:\n" . $message;
$headers = 'From: ' . $_POST['email'] . "\r\n" .
'Reply-To: ' . $_POST["email"] . '' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// mail($to, $subject, $message);
} else {
$error = 1;
}
}
?>
<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="content">
<h2>Contact</h2>
<?php
if (!isset($sent) || !$sent) {
?><p>Fill in a message to us below and we'll get back to you as soon as possible.</p><div class="contact"><form method="POST" action="">
<?php if ($error != NULL) { ?>
<div class="alert alert-danger"><h4>You need to click the ReCaptcha!</h4><p>Don't forget to click the "I'm not a robot" button.</p></div>
<?php } ?>
<input type="email" id="email" name="email" placeholder="Your email" required="" class="form-control"/>
<textarea rows="4" id="message" name="message" cols="50" required="" placeholder="Message"></textarea>
<div class="g-recaptcha" data-sitekey="<?php echo $siteKey; ?>"></div>
<script type="text/javascript"
src="https://www.google.com/recaptcha/api.js?hl=<?php echo $lang; ?>">
</script>
<button name="post" id="post" type="submit" class="btn btn-lg btn-success">Send</button></form></div><?php } else {
?>
<center><div class="alert alert-success" role="alert" style="height: 100px;width: 500px">Email sent!<br><br>Thank you for your email. A reply will be sent to: <?php echo $email; ?></div></center>
<?php
}
?>
</div>
<?php include './res/footer.php'; ?>