-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsend_booking.php
35 lines (31 loc) · 1.42 KB
/
send_booking.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
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = htmlspecialchars($_POST['name']);
$mail = htmlspecialchars($_POST['mail']);
$phone = htmlspecialchars($_POST['phone']);
$car = htmlspecialchars($_POST['car']);
$comments = htmlspecialchars($_POST['comments']);
$cartData = json_decode($_POST['cart-data'], true); // Decode JSON cart data
if (!empty($name) && !empty($phone) && !empty($car) && !empty($mail)) {
$to = "[email protected]"; // Replace with your email address
$subject = "Bestilling via mrtuning.dk";
// Format cart data
$cartMessage = "Products:\n";
foreach ($cartData as $item) {
$extraInfo = $item['withTuning'] ? "" : " + (uden tuning.)";
$cartMessage .= "- {$item['name']}{$extraInfo}: {$item['quantity']} x {$item['price']} kr.\n";
}
// Construct the email message
$message = "Name: $name\nEmail: $mail\nPhone: $phone\nCar Model: $car\n\n$cartMessage\nComments: $comments";
$headers = "From: [email protected]";
// Send email
if (mail($to, $subject, $message, $headers)) {
echo "Mange tak for din bestilling! Vi vender tilbage til dig indenfor 1-2 dage.";
} else {
echo "Beklager, noget gik galt i vores ende. Kan du prøve en gang mere?";
}
} else {
echo "Husk og udfyld alle felterne.";
}
}
?>