1

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');

  • 1
    You should post your code so folks can assist you. – ckpepper02 May 8 '13 at 18:46
  • code has been added :) – Karl May 8 '13 at 19:18
0

Put this after your if empty $errors and edit to meet your needs:

if(empty($errors)) {
$subject = __('[Your Subject]', 'your_text_domain').' '.$title;
$body = __("Name: ","your_text_domain").$booking_name;
$body .= __("\n\nEmail: ","your_text_domain").$booking_email;
$body .= __("\n\nPhone: ","your_text_domain").$booking_phone;
$body .= __("\n\nMessage: ","your_text_domain").$message;

$headers = __('From: your@email.com ', 'your_text_domain').' <'.$booking_email.'>' . "\r\n" . __('Reply-To: ','your_text_domain') . $email; // Change this $email to whatever you want where you will get messages from booked persons

$mail_sent = false;
$mail_sent = mail($mailto, $subject, $body, $headers);

if ($mail_sent == true) {
    echo __('Your message has been sent succesfully.','your_text_domain');      
} else {
    $error = true;
    echo __('Sorry, an error occured while sending your message. Please try again.','your_text_domain');        
    }
}   

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.