-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathestimate.php
More file actions
142 lines (119 loc) · 5.23 KB
/
Copy pathestimate.php
File metadata and controls
142 lines (119 loc) · 5.23 KB
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
<?php
// Make sure all required fields are present and filled in
if (!isset($_POST['FirstName']) || !isset($_POST['LastName']) || !isset($_POST['Email' ]) ||
!isset($_POST['Phone' ]) || !isset($_POST['Address' ]) || !isset($_POST['City' ]) ||
!isset($_POST['State' ]) || !isset($_POST['Zipcode' ]) || !isset($_POST['StartDate']) ||
!isset($_POST['Time' ]) || !isset($_POST['g-recaptcha-response']) ||
empty($_POST['FirstName']) || empty($_POST['LastName']) || empty($_POST['Email' ]) ||
empty($_POST['Phone' ]) || empty($_POST['Address' ]) || empty($_POST['City' ]) ||
empty($_POST['State' ]) || empty($_POST['Zipcode' ]) || empty($_POST['StartDate']) ||
empty($_POST['Time' ]) || empty($_POST['g-recaptcha-response'])) {
http_response_code(400);
echo("Invalid request");
exit(0);
}
$firstName = trim(stripslashes(htmlspecialchars($_POST['FirstName'])));
$lastName = trim(stripslashes(htmlspecialchars($_POST['LastName' ])));
$email = trim(stripslashes(htmlspecialchars($_POST['Email' ])));
$phone = trim(stripslashes(htmlspecialchars($_POST['Phone' ])));
$address = trim(stripslashes(htmlspecialchars($_POST['Address' ])));
$city = trim(stripslashes(htmlspecialchars($_POST['City' ])));
$state = trim(stripslashes(htmlspecialchars($_POST['State' ])));
$zipCode = trim(stripslashes(htmlspecialchars($_POST['Zipcode' ])));
$startDate = trim(stripslashes(htmlspecialchars($_POST['StartDate'])));
$time = trim(stripslashes(htmlspecialchars($_POST['Time' ])));
$other = null;
$comments = null;
$services = $_POST['ServicesList'];
foreach ($services as &$service) {
$service = trim(stripslashes(htmlspecialchars($service)));
if ($service == "Other" && isset($_POST['Other'])) {
$other = trim(stripslashes(htmlspecialchars($_POST['Other'])));
}
}
if( isset($_POST['Comments']) ){
trim(stripslashes(htmlspecialchars($_POST['Comments'])));
}
$api_key = file_get_contents('/api-keys/invisiblerecaptcha.key');
// Verify Captcha
try {
$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = ['secret' => $api_key,
'response' => $_POST['g-recaptcha-response'],
'remoteip' => $_SERVER['REMOTE_ADDR']];
$options = [
'http' => [
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
]
];
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$valid_captcha = json_decode($result)->success;
}
catch (Exception $e) {
$valid_captcha = false;
}
if (!$valid_captcha) {
http_response_code(400);
echo("Invalid captcha");
exit(0);
}
// Store the estimate in the database
/*$database_key = file_get_contents('/api-keys/database.key');
$mysqli_con = new mysqli("localhost","http",$database_key,"cleanlineslawncare");
$valid_database = false;
if(!mysqli_connect_errno()){
$valid_database = true;
$sql = "INSERT IGNORE INTO estimates (full_name, email_address, message, message_date) VALUES ( ? , ? , ? ,'" . date("Y-m-d H:i:s") . "');";
if($stmt = $mysqli_con->prepare($sql)){
$stmt->bind_param('sss', $name, $email, $message);
$stmt->execute();
$stmt->store_result();
$stmt->close();
} else {
$valid_database = false;
}
}
$mysqli_con->close();
if( !$valid_database ){
http_response_code(500);
echo("Invalid database");
exit(0);
}*/
// Format email to be sent
$message = "First Name: " . $firstName . "\n";
$message .= "Last Name: " . $lastName . "\n";
$message .= "Email: " . $email . "\n";
$message .= "Phone: " . $phone . "\n\n";
$message .= $address . "\n";
$message .= $city . ", " . $state . " " . $zipCode . "\n\n";
$message .= "Services: \n";
foreach ($services as &$service) {
if( $service === "Other" ){
$message .= " " . $service . ": " . $other . "\n";
} else {
$message .= " " . $service . "\n";
}
}
$message .= "\nStart Date : " . $startDate . "\n";
$message .= "Time of Day: " . $time . "\n";
if ($comments != null && !empty($comments)) {
$message .= "Comments : " . $comments . "\n";
}
// Send the estimate request to email
mail("exmark845@gmail.com",
"Estimate Request - " . $firstName . " " . $lastName,
$message,
'From: estimate@cleanlineslawncare.com' . "\r\n" .
'Reply-To: ' . $email . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-Type: text/plain; charset=utf-8' . "\r\n" .
'X-Priority: 1' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n"
);
http_response_code(200);
echo("Success!");
exit(0);
?>