-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact_form.php
59 lines (52 loc) · 2.22 KB
/
contact_form.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
if (isset($_POST["submit"])) {
$name = htmlspecialchars($_POST['name']);
$email = htmlspecialchars($_POST['email']);
$subject = htmlspecialchars($_POST['subject']);
$message = htmlspecialchars($_POST['message']);
$human = intval(htmlspecialchars($_POST['human']));
$from = 'nostradamiq.org LandingPage ContactForm';
$to = '[email protected]';
// Render Body:
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
// initialize error check:
$NameErr = false;
$EmailErr = false;
$IssueErr = false;
$MessageErr = false;
$HumanErr = false;
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter Your name';
$NameErr = true;
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = '<p class="text-danger">Please enter Your real Email address! We want to write back to You!</p>';
$EmailErr = true;
}
// Check if Subject has been entered
if (!$_POST['subject']) {
$errIssue = '<p class="text-danger">Please select a subject!</p>';
$IssueErr = true;
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = '<p class="text-danger">Please enter Your message!</p>';
$MessageErr = true;
}
//Check if simple anti-bot test is correct
if ($human !== 5) {
$errHuman = '<p class="text-danger">Your anti-spam is incorrect!</p>';
$HumanErr = true;
}
// If there are no errors, send the email
if (!$NameErr && !$EmailErr && !$IssueErr && !$MessageErr && !$HumanErr) {
if (mail ($to, $subject, $body, $from)) {
$result = '<div class="alert alert-success">Thank You! We will be in touch with You soon!</div>';
} else {
$result = '<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later</div>';
}
}
}
?>