I have coded a front-end form that posts to a custom post type, i have a form input field for an email and when the form posts to the custom post type i want an email sent to the email address inserted into the email input when it’s submitted.
Any ideas??
Edit…Here’s my code (forgot lol)
if('POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) && $_POST['action'] == "new_booking") {
if(isset($_POST['submit'])) {
$sucess = "We will contact you regarding this booking.";
$errors = "";
if(!empty($_POST['booking_name'])) {
$booking_name = trim($_POST['booking_name']);
} else {
$errors .= "<li>Please enter your name.</li>";
}
if(!empty($_POST['booking_email'])) {
$booking_email = trim($_POST['booking_email']);
} else {
$errors .= "<li>Please enter your email.</li>";
}
if(!empty($_POST['booking_address'])) {
$booking_address = trim($_POST['booking_address']);
} else {
$errors .= "<li>Please enter your address.</li>";
}
if(!empty($_POST['booking_phone'])) {
$booking_phone = trim($_POST['booking_phone']);
} else {
$errors .= "<li>Please enter your phone number.</li>";
}
if(!empty($_POST['booking_rooms'])) {
$booking_rooms = trim($_POST['booking_rooms']);
} else {
$errors .= "<li>Please enter number of rooms.</li>";
}
if(!empty($_POST['booking_adults'])) {
$booking_adults = $_POST['booking_adults'];
} else {
$errors .= "<li>Please enter number of adults.</li>";
}
if(!empty($_POST['booking_arrival'])) {
$booking_arrival = trim($_POST['booking_arrival']);
} else {
$errors .= "<li>Please enter an arrival date.</li>";
}
if(!empty($_POST['booking_departure'])) {
$booking_departure = trim($_POST['booking_departure']);
} else {
$errors .= "<li>Please enter a departure date.</li>";
}
$booking_requirements = trim($_POST['booking_requirements']);
if(empty($errors)) {
$new_booking = array(
'post_title' => $booking_name,
'post_status' => 'publish',
'post_type' => 'listings',
'booking_email' => $booking_email,
'booking_address' => $booking_address,
'booking_phone' => $booking_phone,
'booking_rooms' => $booking_rooms,
'booking_adults' => $booking_adults,
'booking_arrival' => $booking_arrival,
'booking_departure' => $booking_departure,
'booking_requirements' => $booking_requirements
);
$pid = wp_insert_post($new_booking);
add_post_meta($pid, 'booking_email', $booking_email, true);
add_post_meta($pid, 'booking_address', $booking_address, true);
add_post_meta($pid, 'booking_phone', $booking_phone, true);
add_post_meta($pid, 'booking_rooms', $booking_rooms, true);
add_post_meta($pid, 'booking_adults', $booking_adults, true);
add_post_meta($pid, 'booking_arrival', $booking_arrival, true);
add_post_meta($pid, 'booking_departure', $booking_departure, true);
add_post_meta($pid, 'booking_requirements', $booking_requirements, true);
}
}
}
do_action(‘wp_insert_post’, ‘wp_insert_post’);
Put this after your if empty $errors and edit to meet your needs: