-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhelp.php
56 lines (48 loc) · 1.21 KB
/
help.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
<?php
include("init.php");
if($_SERVER['REQUEST_METHOD']=="POST"){
// Inputs
$name = trim($_POST['name']);
$useremail = trim($_POST['useremail']);
$sub = test_input($_POST['subject']);
$body = test_input($_POST['body']);
// Verification
$error = array();
if(empty($name)){
$error[] = "Require name";
}
if (empty($useremail)) {
$error[] = "Require email";
} else {
if (!filter_var($useremail, FILTER_VALIDATE_EMAIL)) {
$error[] = "Invalid email format";
}
}
if(empty($body)){
$error[] = "Require Body";
}
// Send
if(!empty($error)){
$response['status']=400;
$response['messages']=$error;
echo json_encode($response);
}
else{
$email = "saar@iitp.ac.in";
$subject = "Alumni $name wants to say something.";
$msg = "Alumni Name : $name <br>
Alumni Email : $useremail <br><br>
Subject : $subject <br><br>
Message, <br>
$body ";
if(send_email($email, $subject, $msg, $useremail)){
$response['status'] = 202;
$response['message'] = "Successful";
echo json_encode($response);
} else {
$response['status'] = 400;
$response['message'] = "Unable to send email";
echo json_encode($response);
}
}
}