-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.php
111 lines (99 loc) · 3.66 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
include('header.php');
?>
<h1>Contact Us</h1>
<hr class="short-fat" />
<?php
if(!empty($_POST)){
if (!empty($_SERVER['HTTP_CLIENT_IP'])) $ip = $_SERVER['HTTP_CLIENT_IP'];
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
else $ip = $_SERVER['REMOTE_ADDR'];
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => http_build_query(
array(
'secret' => "6LeZFRoTAAAAAFkYrIE3hhmp4XUoxWLlAChxoMM_",
'response' => $_POST['g-recaptcha-response'],
'remoteip' => $ip
)
)
)
);
$context = stream_context_create($opts);
$result = json_decode( file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context));
if($result->success == false) echo "<div class='alert alert-danger'> BOT ALERT </div>";
else {
$to = $admin_info['email'];
$subject = "New Message from ELH Contact Form";
$message = "New message from ELH Contact Form\r\n\r\n";
$message .= "Name: {$_POST['name']}\r\n";
$message .= "Email: {$_POST['email']}\r\n";
$message .= "Phone: {$_POST['phone']}\r\n";
$message .= "User Type: {$_POST['usertype']}\r\n\r\n";
$message .= "Message: \r\n\r\n";
$message .= $_POST['message'];
$headers = 'From: ' . $_POST['name'] . ' <'.$_POST['email'] . '>'."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
echo "<div class='alert alert-success'> Message Sent </div>";
}
}
else {
$user = false;
if(login_type() == 'teacher') $user = get_teacher(login_id());
else if (login_type() == 'student') $user = get_student(login_id());
?>
<form method="post" data-enable-shim="true">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="sr-only" for="name">Name</label>
<input type="text" class="form-control" id="name" placeholder="Name" name="name" value="<?php if(logged_in()) echo $user->name; ?>" required>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="sr-only" for="usertype">User Type</label>
<select class="form-control" id="usertype" name="usertype">
<option disabled selected>User Type</option>
<option value="teacher" <?php if(logged_in() && login_type() == 'teacher') echo "SELECTED"; ?> >Teacher</option>
<option value="student" <?php if(logged_in() && login_type() == 'student') echo "SELECTED"; ?> >Student</option>
</select>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label class="sr-only" for="phone">Phone Number</label>
<input type="phone" class="form-control" id="phone" name="phone" placeholder="Phone Number">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="sr-only" for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Email" value="<?php if(logged_in()) echo $user->email; ?>" required>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<textarea class="form-control" rows="3" name="message" placeholder="Message" required></textarea>
</div>
</div>
<div class="row" style="margin-top: 10px;">
<div class="col-md-7"></div>
<div class="col-md-3 text-right">
<div class="g-recaptcha" data-sitekey="6LeZFRoTAAAAAJAdCKUCvHtDTFlEJl-DsnadUtmB"></div>
</div>
<div class="col-md-2 text-right">
<input class="btn btn-primary" type="submit" value="Send">
</div>
</div>
</form>
<?php
}
?>
<?php include('footer.php'); ?>