HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/kevin-demo/wp-content/themes/fitmencook/includes/klaviyoEmailSendAjax.php
<?php
add_action('wp_ajax_klaviyo_email_send', 'klaviyo_email_send');
add_action('wp_ajax_nopriv_klaviyo_email_send', 'klaviyo_email_send');

function klaviyo_email_send () {

    $user_email = isset($_POST['userEmail']) ? wp_strip_all_tags($_POST['userEmail']) : "";
    $post_url = isset($_POST['postUrl']) ? wp_strip_all_tags($_POST['postUrl']) : "";
    $recipeID = isset($_POST['recipeID']) ? wp_strip_all_tags($_POST['recipeID']) : "";

    if($user_email && $post_url && $recipeID) {

        if(filter_var($user_email, FILTER_VALIDATE_EMAIL) && preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i", $post_url)) {

            $subject = 'Saved Recipe: ' . get_the_title($recipeID) . ' - FitMenCook';

            // Get recipe template

            $recipe_template =  get_page_template_slug($recipeID);

            ob_start();

            if($recipe_template == 'single-recipes-multiple.php') {
                get_template_part('template-parts/recipe/newsletter-email-multiple-template', null, [
                    'recipeID' => $recipeID
                ]);
            }

            elseif($recipe_template == 'single-recipes-collection.php') {
                get_template_part('template-parts/recipe/newsletter-email-collection-template', null, [
                    'recipeID' => $recipeID
                ]);
            }

            else {
                get_template_part('template-parts/recipe/newsletter-email-default-template', null, [
                    'recipeID' => $recipeID
                ]);
            }

            $mess = ob_get_clean();

            $headers = array('Content-Type: text/html; charset=UTF-8');

            $email_send = wp_mail($user_email, $subject, $mess, $headers);

            if($email_send) {
                wp_send_json_success();
            }
        }

        else {
            wp_send_json_error(null, 400);
        }
    }

    else {
        wp_send_json_error(null, 400);
    }

    die();
}