<?php if (!empty($_POST) && array_key_exists('contact-form', $_POST)) { ?> <?php $is_form_filled = !empty($_POST['email']) && !empty($_POST['subject']) && !empty($_POST['message']); $is_recaptcha = Realia_Recaptcha::is_recaptcha_enabled(); $is_recaptcha_valid = array_key_exists('g-recaptcha-response', $_POST) ? Realia_Recaptcha::is_recaptcha_valid($_POST['g-recaptcha-response']) : false; ?> <?php if (!($is_recaptcha && !$is_recaptcha_valid) && $is_form_filled) { ?> <?php $result = wp_mail($_POST['email'], $_POST['subject'], $_POST['message']); ?> <?php if ($result) { ?> <div class="alert alert-success"><?php echo __('Your message has been successfully sent.', 'realia'); ?> </div> <?php } else { ?> <div class="alert alert-warning"><?php echo __('An error occured when sending an email.', 'realia');
/** * Process enquire form * * @access public * @return void */ public static function process_enquire_form() { if (!isset($_POST['enquire_form']) || empty($_POST['post_id'])) { return; } $post = get_post($_POST['post_id']); $email = esc_html($_POST['email']); $name = esc_html($_POST['name']); $subject = __('Message from enquire form', 'realia'); $headers = sprintf("From: %s <%s>\r\n Content-type: text/html", $name, $email); $is_recaptcha = Realia_Recaptcha::is_recaptcha_enabled(); $is_recaptcha_valid = array_key_exists('g-recaptcha-response', $_POST) ? Realia_Recaptcha::is_recaptcha_valid($_POST['g-recaptcha-response']) : false; ob_start(); include Realia_Template_Loader::locate('mails/enquire'); $message = ob_get_contents(); ob_end_clean(); $emails = array(); // Author if (!empty($_POST['receive_author'])) { $emails[] = get_the_author_meta('user_email', $post->post_author); } // Admin if (!empty($_POST['receive_author'])) { $emails[] = get_bloginfo('admin_email'); } // Agent if (!empty($_POST['receive_agent'])) { $agent = Realia_Query::get_property_agent($post->ID); if (!empty($agent)) { $email = get_post_meta($agent->ID, REALIA_AGENT_PREFIX . 'email', true); if (!empty($email)) { $emails[] = $email; } } } // Default fallback if (empty($_POST['receive_admin']) && empty($_POST['receive_agent']) && empty($_POST['receive_author'])) { $emails[] = get_the_author_meta('user_email', $post->post_author); } $emails = array_unique($emails); if ($is_recaptcha && $is_recaptcha_valid) { $_SESSION['messages'][] = array('danger', __('CAPTCHA is not valid.', 'realia')); } foreach ($emails as $email) { $status = wp_mail($email, $subject, $message, $headers); } if (!empty($status) && $status == 1) { $_SESSION['messages'][] = array('success', __('Message has been successfully sent.', 'realia')); } else { $_SESSION['messages'][] = array('danger', __('Unable to send a message.', 'realia')); } }