forked from rpiambulance/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.email_submit.php
173 lines (144 loc) · 5.86 KB
/
.email_submit.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
// grab recaptcha library
require_once ".recaptchalib.php";
// grab secret key and to-address
require_once ".form_config.php";
// empty response
$response = null;
// check secret key
$reCaptcha = new ReCaptcha($secret);
$errors = array();
// array to pass back data
$data = array();
// Get the input ===============================================================
$formData = file_get_contents('php://input');
$input = json_decode($formData, true);
// if submitted check response
if (isset($input['g-recaptcha-response'])) {
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$input["g-recaptcha-response"]
);
}
if ($response == null) {
$errors['reCaptcha'] = 'You did not validate your submission with our reCaptcha.';
} else if($response != null && !$response->success) {
$errors['reCaptcha'] = 'Your reCaptcha verification did not succeed. Please try again.';
}
// validate the variables ======================================================
if (!isset($input['orgName'])) {
$errors['orgName'] = 'Organization Name is required.';
}
if (!isset($input['name'])) {
$errors['name'] = 'Contact Name is required.';
}
if (!isset($input['email'])) {
$errors['email'] = 'Email is required.';
}
if (!isset($input['phone'])) {
$errors['phone'] = 'Phone number is required.';
}
if (!isset($input['eventName'])) {
$errors['eventName'] = 'Event name is required.';
}
if (!isset($input['loc'])) {
$errors['loc'] = 'Event location is required.';
}
if (!isset($input['date'])) {
$errors['date'] = 'Event date is required.';
}
if (!isset($input['time'])) {
$errors['time'] = 'Event time is required.';
}
if (!isset($input['type'])) {
$errors['type'] = 'Event type is required.';
}
if (!isset($input['attendance'])) {
$errors['attendance'] = 'Event attendance is required.';
}
if (!isset($input['duration'])) {
$errors['duration'] = 'Event duration is required.';
}
if (!isset($input['tier'])) {
$errors['tier'] = 'Tier is required.';
}
// return a response ===========================================================
if (!empty($errors)) {
// if there are items in our errors array, return those errors
$data['success'] = false;
$data['errors'] = $errors;
$data['messageError'] = 'Please check the fields in red';
} else {
// if there are no errors, return a message
$data['success'] = true;
$data['messageSuccess'] = 'Thanks for reaching out! We will get back to you soon as possible!';
// LOAD INPUT INTO TEMP VARIABLES ****
$orgName = $input['orgName'];
$name = $input['name'];
$email_from = $input['email'];
$phone = $input['phone'];
$eventName = $input['eventName'];
$loc = $input['loc'];
$date = $input['date'];
$time = $input['time'];
$type = $input['type'];
$attendance = $input['attendance'];
$duration = $input['duration'];
$tier = $input['tier'];
// ***********************************
// CONSTANTS *************************
$email_subject = "RPI Ambulance Coverage Request: " . $orgName;
// ***********************************
// EMAIL TO THE O-BOARD ************************
$email_message = "A coverage request was processed by the RPI Ambulance website. " .
"Submission details can be found below:\n" .
"Tier Requested: " . $tier . "\n" .
"\nContact Information:\n".
"\nOrganization Name: " . $orgName . "\n" .
"\nContact Name: " . $name . "\n" .
"Email: " . $email_from . "\n" .
"Phone: " . $phone . "\n" .
"\nEvent Information:\n".
"\nEvent Name: " . $eventName . "\n" .
"Location: " . $loc . "\n" .
"Date: " . $date . "\n" .
"Arrival Time: " . $time . "\n" .
"Type: " . $type . "\n" .
"Attendance: " . $attendance . "\n" .
"Duration: " . $duration . " hour(s)\n";
$headers = 'From: ' . $email_from . "\r\n" .
'Reply-To: ' . $email_from . "\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
// EMAIL TO THE REQUESTER ************************
// CONSTANTS *************************
$email_subject_requester = "Your RPI Ambulance Coverage Request for: " . $eventName;
// ***********************************
$email_message_requester= "Thanks for asking us to cover your event! Since this is an automated email message, one ".
"of our officers should be reaching out to you regarding your request soon with some more information. For your ".
"records, we've included a copy of the request below:\n\n".
"Tier Requested: " . $tier . "\n" .
"\nContact Information:\n".
"\nOrganization Name: " . $orgName . "\n" .
"Contact Name: " . $name . "\n" .
"Email: " . $email_from . "\n" .
"Phone: " . $phone . "\n" .
"\nEvent Information:\n".
"\nEvent Name: " . $eventName . "\n" .
"Location: " . $loc . "\n" .
"Date: " . $date . "\n" .
"Arrival Time: " . $time . "\n" .
"Type: " . $type . "\n" .
"Attendance: " . $attendance . "\n" .
"Duration: " . $duration . " hour(s)\n".
"\nPlease verify that the above information is correct. If you do notice an error, just let us know once you receive ".
"an email from a real-life human. If you have any further questions feel free to reach our to us on our website, ".
"or at [email protected].\n".
"\nThanks again for the request and we'll be in touch with you soon!\n".
"\n--The RPI Ambulance Team";
$headers_requester= "From: [email protected] \r\n".
'X-Mailer: PHP/' . phpversion();
@mail($email_from,$email_subject_requester,$email_message_requester,$headers_requester);
}
// return all our data to an AJAX call =========================================
echo json_encode($data);