Created
November 3, 2018 13:56
-
-
Save luisciphere/230d09416baabc0aee8c942ae8cdd9ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// проверка на спам - просто прерываем выполнение кода, при желании можно и сообщение спамерам вывести | |
if( isset( $_POST['comment'] ) || isset( $_POST['message'] ) ) | |
exit; | |
// подключаем WP, можно конечно обойтись без этого, но зачем? | |
require( dirname(__FILE__) . '/wp-load.php'); | |
$name = ($_POST['name']) ? $_POST['name'] : ''; | |
$email = ($_POST['email'] && is_email( $_POST['email'] )) ? $_POST['email'] : ''; | |
$phone = ($_POST['phone']) ? $_POST['phone'] : ''; | |
$request = ($_POST['facility-requested']) ? $_POST['facility-requested'] : ''; | |
$date = ($_POST['reservation-date']) ? $_POST['reservation-date'] : ''; | |
$type = ($_POST['type-of-event']) ? $_POST['type-of-event'] : ''; | |
$number_guests = ($_POST['number-of-guests']) ? $_POST['number-of-guests'] : ''; | |
$subscribe = ($_POST['subscribe-newsletter']) ? $_POST['subscribe-newsletter'] : false; | |
// следующий шаг - проверка на обязательные поля, у нас это емайл, имя и сообщение | |
if( !empty($name) && !empty($email) && !empty($phone) ) { | |
$message = "Name: $name;<br>"; | |
$message .= "Email: $email;<br>"; | |
$message .= "Phone: $phone;<br>"; | |
$message .= "Request a reservation: $request;<br>"; | |
$message .= "Reservation Date: $date;<br>"; | |
$message .= "Type of Event: $type;<br>"; | |
$message .= "Number of Guests: $number_guests;<br>"; | |
$message .= "Subscribe: $subscribe;<br>"; | |
echo $message; | |
echo "<pre>"; | |
print_r($_POST); | |
add_filter( 'wp_mail_content_type', function($content_type){ | |
return "text/html"; | |
}); | |
if(wp_mail( '[email protected]', 'Request a reservation', $message )) | |
{ | |
echo "OK"; | |
}; | |
// $headers = array( | |
// "Content-type: text/html; charset=utf-8", | |
// "From: " . $_POST['name'] . " <" . $_POST['email'] . ">" | |
// ); | |
// | |
// if( wp_mail( get_option('admin_email'), 'Сообщение с сайта', wpautop( $_POST['soobschenie'] ), $headers ) ) { | |
// header('Location:' . site_url('/contact?msg=success') ); | |
// exit; | |
// } | |
} | |
//header('Location:' . site_url('/contact?msg=error') ); | |
//exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment