first commit
This commit is contained in:
35
wp-content/themes/skysafe/inc/reservation-handler.php
Normal file
35
wp-content/themes/skysafe/inc/reservation-handler.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
add_action('wp_ajax_send_reservation', 'handle_reservation');
|
||||
add_action('wp_ajax_nopriv_send_reservation', 'handle_reservation');
|
||||
|
||||
function handle_reservation() {
|
||||
$name = sanitize_text_field($_POST['name']);
|
||||
$plate = sanitize_text_field($_POST['plate']);
|
||||
$arrival = sanitize_text_field($_POST['arrival']);
|
||||
$departure = sanitize_text_field($_POST['departure']);
|
||||
$email = sanitize_email($_POST['email']);
|
||||
$phone = sanitize_text_field($_POST['phone']);
|
||||
$privacy = isset($_POST['privacy']) ? "Tak" : "Nie";
|
||||
|
||||
$to = "twoj_email@domena.pl";
|
||||
$subject = "Nowa rezerwacja miejsca parkingowego";
|
||||
$message = "
|
||||
Imię i nazwisko: $name
|
||||
Nr rejestracyjny: $plate
|
||||
Data przyjazdu: $arrival
|
||||
Data wyjazdu: $departure
|
||||
Email: $email
|
||||
Telefon: $phone
|
||||
Zgoda na kontakt: $privacy
|
||||
";
|
||||
|
||||
$headers = ["Content-Type: text/plain; charset=UTF-8"];
|
||||
|
||||
$sent = wp_mail($to, $subject, $message, $headers);
|
||||
|
||||
if ($sent) {
|
||||
wp_send_json_success(["message" => "Dziękujemy! Rezerwacja została wysłana."]);
|
||||
} else {
|
||||
wp_send_json_error(["message" => "Błąd wysyłki. Spróbuj ponownie."]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user