-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmail_form.php
51 lines (44 loc) · 1.42 KB
/
mail_form.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
<?php
require_once('recaptchalib.php');
$EMAIL_ADDRESSES =
array(
);
// Verify that we're sending our message to a valid email
$recipient = $_POST['sendtoemail'];
if (! in_array($recipient, $EMAIL_ADDRESSES, TRUE)) {
header("Location: failure.php");
exit;
}
// Replace newlines to prevent header insertion
$name = preg_replace('/\R/u', '', $_POST['f1']);
$email = preg_replace('/\R/u', '', $_POST['f2']);
// Validate email, this is probably less than great
$email = filter_var($email, FILTER_VALIDATE_EMAIL);
if (!$email) {
header("Location: failure.php");
exit;
}
// Run reCAPTCHA validation
$privatekey = "6LdMJeISAAAAACVSv8XpbNPCBNlxgxYytXoG15nY";
$capchaResponse = $_POST["recaptcha_response_field"];
if (!$capchaResponse) {
header("Location: failure.php");
exit;
}
$resp = recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
header("Location: failure.php");
exit;
}
$message = $_POST['f3'];
$formcontent="From: $name \nEmail: $email \nMessage: $message";
$subject = "A message from the public website";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
header("Location: thankyou.php");
?>