-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_mail.php
29 lines (25 loc) · 948 Bytes
/
send_mail.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
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$to = "[email protected]"; // Replace with the recipient's email address
$headers = "From: $email\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
// Create the email message
$emailMessage = "Name: $name\n";
$emailMessage .= "Email: $email\n";
$emailMessage .= "Subject: $subject\n";
$emailMessage .= "Message:\n$message";
// Send the email using Gmail SMTP
if (mail($to, $subject, $emailMessage, $headers)) {
header("Location: success.html"); // Redirect to a success page
} else {
header("Location: error.html"); // Redirect to an error page
}
} else {
// If someone tries to access this script directly, redirect them to the form page
header("Location: contact.html");
}
?>