-
Notifications
You must be signed in to change notification settings - Fork 1
/
form.php
45 lines (36 loc) · 1.21 KB
/
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
<?php
$data = json_decode(file_get_contents('php://input'), true);
$name=""; $email=""; $message=""; $captcha=""; $to=""; $from=""; $subject=""; $body="";
if(isset($data['name'])){
$name=$data['name'];
}
if(isset($data['email'])){
$email=$data['email'];
}
if(isset($data['message'])){
$message=$data['message'];
}
if(isset($data['g-recaptcha-response'])){
$captcha=$data['g-recaptcha-response'];
}
if($captcha !== '' && !$captcha){
http_response_code(400);
exit;
}
$from = 'Contact Form';
$to = '[email protected]';
$subject = 'Message from Contact Form';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
session_start();
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LdW6RQTAAAAAFjQ6gMirvZmRKvLjHX5Il01Lfpw&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response == false)
{
http_response_code(400);
}else if (mail ($to, $subject, $body, $from))
{
http_response_code(200);
}else {
http_response_code(400);
}
session_destroy();
?>