forked from duotics/web-freimo-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appointment.php
132 lines (110 loc) · 3.46 KB
/
appointment.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
<?php
/**
* EDIT THE VALUES BELOW THIS LINE TO ADJUST THE CONFIGURATION
* EACH OPTION HAS A COMMENT ABOVE IT WITH A DESCRIPTION
*/
/**
* Specify the email address to which all mail messages are sent.
* The script will try to use PHP's mail() function,
* so if it is not properly configured it will fail silently (no error).
*/
$mailTo = '[email protected]';
/**
* Set the message that will be shown on success
*/
$successMsg = 'Thank you, mail sent successfuly!';
/**
* Set the message that will be shown if not all fields are filled
*/
$fillMsg = 'Please fill all fields!';
/**
* Set the message that will be shown on error
*/
$errorMsg = 'Hm.. seems there is a problem, sorry!';
/**
* DO NOT EDIT ANYTHING BELOW THIS LINE, UNLESS YOU'RE SURE WHAT YOU'RE DOING
*/
?>
<?php
if(
!isset($_POST['patient-name']) ||
!isset($_POST['patient-email']) ||
!isset($_POST['patient-date']) ||
!isset($_POST['patient-time']) ||
!isset($_POST['patient-department']) ||
!isset($_POST['patient-message']) ||
empty($_POST['patient-name']) ||
empty($_POST['patient-email']) ||
empty($_POST['patient-date']) ||
empty($_POST['patient-time']) ||
empty($_POST['patient-department']) ||
empty($_POST['patient-message'])
) {
if( empty($_POST['patient-name']) && empty($_POST['patient-email']) ) {
$json_arr = array( "type" => "error", "msg" => $fillMsg );
echo json_encode( $json_arr );
} else {
$fields = "";
if( !isset( $_POST['patient-name'] ) || empty( $_POST['patient-name'] ) ) {
$fields .= "Name";
}
if( !isset( $_POST['patient-email'] ) || empty( $_POST['patient-email'] ) ) {
if( $fields == "" ) {
$fields .= "Email";
} else {
$fields .= ", Email";
}
}
if( !isset( $_POST['patient-date'] ) || empty( $_POST['patient-date'] ) ) {
if( $fields == "" ) {
$fields .= "Day";
} else {
$fields .= ", Day";
}
}
if( !isset( $_POST['patient-time'] ) || empty( $_POST['patient-time'] ) ) {
if( $fields == "" ) {
$fields .= "Time";
} else {
$fields .= ", Time";
}
}
if( !isset( $_POST['patient-department'] ) || empty( $_POST['patient-department'] ) ) {
if( $fields == "" ) {
$fields .= "Department";
} else {
$fields .= ", Department";
}
}
if( !isset( $_POST['patient-message'] ) || empty( $_POST['patient-message'] ) ) {
if( $fields == "" ) {
$fields .= "Message";
} else {
$fields .= ", Message";
}
}
$json_arr = array( "type" => "error", "msg" => "Please fill ".$fields." fields!" );
echo json_encode( $json_arr );
}
} else {
// Validate e-mail
if (!filter_var($_POST['patient-email'], FILTER_VALIDATE_EMAIL) === false) {
$msg = "Name: ".$_POST['patient-name']."\r\n";
$msg .= "Email: ".$_POST['patient-email']."\r\n";
$msg .= "Day: ".$_POST['patient-date']."\r\n";
$msg .= "Time: ".$_POST['patient-time']."\r\n";
$msg .= "Department: ".$_POST['patient-department']."\r\n";
$msg .= "Message: ".$_POST['patient-message']."\r\n";
$success = @mail($mailTo, $_POST['patient-email'], $msg, 'From: ' . $_POST['patient-name'] . '<' . $_POST['patient-email'] . '>');
if ($success) {
$json_arr = array( "type" => "success", "msg" => $successMsg );
echo json_encode( $json_arr );
} else {
$json_arr = array( "type" => "error", "msg" => $errorMsg );
echo json_encode( $json_arr );
}
} else {
$json_arr = array( "type" => "error", "msg" => "Please enter valid email address!" );
echo json_encode( $json_arr );
}
}