-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_email.php
More file actions
36 lines (31 loc) · 1.08 KB
/
Copy pathsend_email.php
File metadata and controls
36 lines (31 loc) · 1.08 KB
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
<?php
// form data
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
// email variables
$to = "club@example.com"; // replace with the club email address
$subject = "Form Submission from $name";
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
$headers .= "Content-Type: text/plain; charset=utf-8\r\n";
// email body
$body = "Message from Entrepreneurship Club contact form:\n\n";
$body .= "Name: $name\n";
$body .= "Email: $email\n";
$body .= "Message: $message\n";
// validate email format and required fields
if (!empty($name) && !empty($email) && !empty($message)) {
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
// use the mail() function (disabled here for localhost simulation)
// mail($to, $subject, $body, $headers);
// rediret to the confirmation page
header("Location: contact.php?status=success");
exit();
} else {
echo "<p>Invalid email format. Please enter a valid email address.</p>";
}
} else {
echo "<p>Failed to submit the message. Please fill out all fields.</p>";
}
?>