-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
74 lines (67 loc) · 2.13 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
<?php
function sanitize($val){
$val = trim($val);
$val = strip_tags($val, "<h1><h2><h3><p><img><a><strong><em><ol><ul><li>");
$val = stripslashes($val);
return $val;
}
function json_response($code = 200, $message = null) {
header_remove();
http_response_code($code);
header("Cache-Control: no-cache");
header('Content-Type: application/json');
$status = array(
200 => '200 OK',
400 => '400 Bad Request',
422 => 'Unprocessable Entity',
500 => '500 Internal Server Error'
);
header('Status: '.$status[$code]);
return json_encode(array(
'status' => $code < 300,
'message' => $message
));
}
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
echo json_response(500, $errstr);
exit();
}
set_error_handler("exception_error_handler");
if(isset($_GET['rsvp'])){
$to = "[email protected], [email protected]";
$from = "[email protected]";
$subject = "RSVP From - ";
$headers = 'From: '.$from;
$subject .= sanitize($_POST['name']);
$email = sanitize($_POST['email']);
$output = "Email: ".$email."\n";
$attendance = sanitize($_POST['attendance']);
$output .= "Attending?: ".$attendance."\n\n";
if(isset($_POST['notes'])){
$notes = sanitize($_POST['notes']);
$output .= "Notes: ".$notes."\n\n";
}
if(isset($_POST['numberAttending'])){
$numberAttending = sanitize($_POST['numberAttending']);
$output .= "Number Attending: ".$numberAttending."\n";
}
if(isset($_POST['name']) && isset($_POST['meal'])){
$name = sanitize($_POST['name']);
$meal = sanitize($_POST['meal']);
$output .= "Name: ".$name."\n";
$output .= "Meal: ".$meal."\n\n";
}
for ($count=1; $count < 10; $count++) {
if(isset($_POST['name-'.$count]) && isset($_POST['meal-'.$count])){
$currentName = sanitize($_POST['name-'.$count]);
$currentMeal = sanitize($_POST['meal-'.$count]);
$output .= "Name: ".$currentName."\n";
$output .= "Meal: ".$currentMeal."\n\n";
}else{
break;
}
}
mail($to, $subject, $output, $headers);
echo json_response(200, 'email sent');
}
?>