-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
59 lines (41 loc) · 1.48 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
<?php
require_once 'class/sendSmsEmail.php';
$_POST = json_decode(file_get_contents("php://input"), true);
$errors = [];
if (!isset($_POST['name'])) {
array_push($errors, ' Name key is Required');
}
if (!isset($_POST['email'])) {
array_push($errors, ' Email Key is Required');
}
if (!isset($_POST['messageText'])) {
array_push($errors, 'messageText Key is Required');
}
if (empty($_POST['name']) || strlen($_POST['name']) < 3) {
array_push($errors, ' Name can not be Empty or less than 3 letters');
}if (empty($_POST['email']) || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
array_push($errors, 'Invalid email address');
}if (empty($_POST['messageText']) || strlen($_POST['messageText']) < 10) {
array_push($errors, 'Why Why and Why are u trying to send small message');
}
sendMessage($errors);
function sendMessage($errors) {
if (count($errors) > 0) {
echo json_encode(['errors' => $errors]);
} else {
$send = new sendSmsEmail();
$send->name = $_POST['name'];
$send->reply_email = $_POST['email'];
$send->message = $_POST['messageText'];
$send->subject = $_POST['name'] . ' Wants to Contact With You';
if ($send->sendEmail()) {
sendSuccess();
} else {
echo json_encode(['errors' => 'Sorry Error Occured,I will Fix This PROMISE!!']);
}
}
}
function sendSuccess() {
echo json_encode(['success' => ' Hurray ! Trust me I will contact with You']);
}
?>