-
Notifications
You must be signed in to change notification settings - Fork 0
/
send-email.php
39 lines (35 loc) · 1.49 KB
/
send-email.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
<?php
$your_email = "[email protected]"; // Your email address where you want to receive the form data
$errors = [];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check for required fields
if (empty($_POST['demo-name'])) {
$errors[] = 'Name is required.';
}
if (empty($_POST['demo-email'])) {
$errors[] = 'Email is required.';
}
if (empty($_POST['demo-category'])) {
$errors[] = 'Subject category is required.';
}
if (empty($_POST['demo-message'])) {
$errors[] = 'Message is required.';
}
// Validate and sanitize the input data
if (!filter_var($_POST['demo-email'], FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Invalid email format.';
}
if (empty($errors)) {
$name = filter_input(INPUT_POST, 'demo-name', FILTER_SANITIZE_STRING);
$email = filter_input(INPUT_POST, 'demo-email', FILTER_SANITIZE_EMAIL);
$subject_category = filter_input(INPUT_POST, 'demo-category', FILTER_SANITIZE_STRING);
$priority = filter_input(INPUT_POST, 'demo-priority', FILTER_SANITIZE_STRING);
$message = filter_input(INPUT_POST, 'demo-message', FILTER_SANITIZE_STRING);
$email_content = "Name: $name\nEmail Address: $email\nSubject Category: $subject_category\nPriority: $priority\nMessage:\n$message\n";
// Mail it
mail($your_email, 'Contact Form Submission', $email_content);
header("Location: index.html?contact=success");
exit;
}
}
?>