forked from acmjec/acmjec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.php
100 lines (81 loc) · 2.61 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
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
<?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@example.com';
/**
* Set the message that will be shown on success
*/
$successMsg = 'Thank you, mail sent successfully!';
/**
* 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['name']) ||
!isset($_POST['email']) ||
!isset($_POST['subject']) ||
empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['subject'])
) {
if( empty($_POST['name']) && empty($_POST['email']) ) {
$json_arr = array( "type" => "error", "msg" => $fillMsg );
echo json_encode( $json_arr );
} else {
$fields = "";
if( !isset( $_POST['name'] ) || empty( $_POST['name'] ) ) {
$fields .= "Name";
}
if( !isset( $_POST['email'] ) || empty( $_POST['email'] ) ) {
if( $fields == "" ) {
$fields .= "Email";
} else {
$fields .= ", Email";
}
}
if( !isset( $_POST['subject'] ) || empty( $_POST['subject'] ) ) {
if( $fields == "" ) {
$fields .= "Subject";
} else {
$fields .= ", Subject";
}
}
$json_arr = array( "type" => "error", "msg" => "Please fill ".$fields." fields!" );
echo json_encode( $json_arr );
}
} else {
// Validate e-mail
if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) {
$msg = "Name: ".$_POST['name']."\r\n";
$msg .= "Email: ".$_POST['email']."\r\n";
$msg .= "Subject: ".$_POST['subject']."\r\n";
if( isset( $_POST['message'] ) && $_POST['message'] != '' ) { $msg .= "Message: ".$_POST['message']."\r\n"; }
$success = @mail($mailTo, $_POST['email'], $msg, 'From: ' . $_POST['name'] . '<' . $_POST['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 );
}
}