405]);
}
// Get form data
$fname = sanitize_text_field($_POST[‘fname’] ?? ”);
$lname = sanitize_text_field($_POST[‘lname’] ?? ”);
$email = sanitize_email($_POST[’email’] ?? ”);
$phone = sanitize_text_field($_POST[‘phone’] ?? ”);
$system = sanitize_text_field($_POST[‘system’] ?? ”);
$role = sanitize_text_field($_POST[‘role’] ?? ”);
$facility = sanitize_text_field($_POST[‘facility’] ?? ”);
$message = sanitize_textarea_field($_POST[‘message’] ?? ”);
// Validate required fields
$errors = [];
if (empty($fname)) $errors[] = ‘First name is required’;
if (empty($lname)) $errors[] = ‘Last name is required’;
if (empty($email) || !is_email($email)) $errors[] = ‘Valid email is required’;
if (empty($system)) $errors[] = ‘System selection is required’;
if (!empty($errors)) {
// Return error response
wp_send_json([
‘success’ => false,
‘message’ => ‘Please fill in all required fields.’,
‘errors’ => $errors
], 400);
}
// Build email content
$admin_email = get_option(‘admin_email’);
$subject = “New Quote Request: {$fname} {$lname} – {$system}”;
$email_body = “New Quote Request Received\n”;
$email_body .= “========================\n\n”;
$email_body .= “Contact Information:\n”;
$email_body .= ” Name: {$fname} {$lname}\n”;
$email_body .= ” Email: {$email}\n”;
$email_body .= ” Phone: {$phone}\n\n”;
$email_body .= “Request Details:\n”;
$email_body .= ” System Interest: {$system}\n”;
$email_body .= ” Role: {$role}\n”;
$email_body .= ” Facility: {$facility}\n\n”;
$email_body .= “Project Details:\n”;
$email_body .= “{$message}\n\n”;
$email_body .= “========================\n”;
$email_body .= “Received: ” . current_time(‘mysql’) . “\n”;
$email_body .= “IP: {$_SERVER[‘REMOTE_ADDR’]}\n”;
// Send email to admin
$email_sent = wp_mail(
$admin_email,
$subject,
$email_body,
[
‘From: ‘ . $email,
‘Reply-To: ‘ . $email
]
);
// Optionally send confirmation email to customer
$customer_subject = “We Received Your Quote Request – Balazs Boxing”;
$customer_body = “Hello {$fname},\n\n”;
$customer_body .= “Thank you for your interest in Ultra-Trak systems. We have received your quote request and will review it shortly.\n\n”;
$customer_body .= “A member of our team will contact you within 1 business day at {$phone} or {$email}.\n\n”;
$customer_body .= “System Requested: {$system}\n”;
$customer_body .= “Facility: {$facility}\n\n”;
$customer_body .= “Best regards,\n”;
$customer_body .= “Balazs Boxing Team\n”;
$customer_body .= “[email protected]”;
wp_mail($email, $customer_subject, $customer_body);
// Return success response
wp_send_json([
‘success’ => true,
‘message’ => ‘Thank you! We have received your quote request and will contact you within 1 business day.’
], 200);
?>