-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_mail.php
More file actions
42 lines (38 loc) · 1.54 KB
/
send_mail.php
File metadata and controls
42 lines (38 loc) · 1.54 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
37
38
39
40
41
42
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$name = filter_var($_POST["fullName"], FILTER_SANITIZE_STRING);
$totalPrice = filter_var($_POST["totalPrice"], FILTER_SANITIZE_STRING);
$paymentMethod = filter_var($_POST["paymentMethod"], FILTER_SANITIZE_STRING);
$address = filter_var($_POST["address"], FILTER_SANITIZE_STRING);
$phone = filter_var($_POST["phone"], FILTER_SANITIZE_STRING);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
die("Invalid email format.");
}
$subject = "Order Confirmation - Thank You for Your Purchase!";
$message = "
<html>
<head>
<title>Order Confirmation</title>
</head>
<body>
<h2>Thank you for your order, $name!</h2>
<p><strong>Total Price:</strong> ₹$totalPrice</p>
<p><strong>Payment Method:</strong> $paymentMethod</p>
<p><strong>Delivery Address:</strong> $address</p>
<p><strong>Phone:</strong> $phone</p>
</body>
</html>
";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "From: orders@yourwebsite.com\r\n";
if (mail($email, $subject, $message, $headers)) {
header("Location: thank_you.html"); // Redirect to Thank You page
exit();
} else {
header("Location: error.html"); // Redirect to an error page if email fails
exit();
}
}
?>