/* ============================================
   CONTACT FORM HANDLER WITH SUCCESS/ERROR
============================================ */

add_action('init', 'hs_handle_contact_form');
function hs_handle_contact_form() {

    if (!isset($_POST['hs_contact_submit'])) {
        return;
    }

    // Create a global variable to store messages
    global $hs_form_message;

    // Sanitize fields
    $name    = sanitize_text_field($_POST['name']);
    $email   = sanitize_email($_POST['email']);
    $message = sanitize_textarea_field($_POST['message']);

    // Basic validation
    if (empty($name) || empty($email) || empty($message)) {
        $hs_form_message = array(
            'type' => 'error',
            'text' => 'Please fill in all fields.'
        );
        return;
    }

    if (!is_email($email)) {
        $hs_form_message = array(
            'type' => 'error',
            'text' => 'Please enter a valid email address.'
        );
        return;
    }

    // Email settings
    $to      = "info@heshmatisolutions.com";
    $subject = "New Contact Form Message from $name";

    $body  = "Name: $name\n";
    $body .= "Email: $email\n\n";
    $body .= "Message:\n$message\n";

    // Brevo‑optimized headers
    $headers = array(
        "From: Heshmati Solutions <info@heshmatisolutions.com>",
        "Reply-To: $email",
        "Content-Type: text/plain; charset=UTF-8",
        "Return-Path: info@heshmatisolutions.com",
        "X-Mailer: PHP/" . phpversion()
    );

    // Send email
    $sent = wp_mail($to, $subject, $body, $headers);

    if ($sent) {
        $hs_form_message = array(
            'type' => 'success',
            'text' => 'Thank you! Your message has been sent successfully.'
        );
    } else {
        $hs_form_message = array(
            'type' => 'error',
            'text' => 'Something went wrong. Please try again later.'
        );
    }
}
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://heshmatisolutions.com/wp-sitemap.xsl" ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://heshmatisolutions.com/</loc><lastmod>2026-04-20T21:14:45+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/shop/</loc><lastmod>2026-05-24T20:50:22+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/cart/</loc><lastmod>2026-05-24T20:50:22+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/checkout/</loc><lastmod>2026-05-24T20:50:22+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/my-account/</loc><lastmod>2026-05-24T20:50:22+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/terms/</loc><lastmod>2026-05-24T20:50:30+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/terms/</loc><lastmod>2026-05-24T20:50:30+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/terms/</loc><lastmod>2026-05-24T20:50:30+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/privacy/</loc><lastmod>2026-05-24T20:50:30+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/privacy/</loc><lastmod>2026-05-24T20:50:30+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/privacy/</loc><lastmod>2026-05-24T20:50:30+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/templates-store/</loc><lastmod>2026-06-09T02:20:57+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/business-finance-template/</loc><lastmod>2026-06-09T02:37:13+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/executive-dashboard/</loc><lastmod>2026-06-09T02:37:23+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/inventory-management-tool/</loc><lastmod>2026-06-09T02:37:32+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/about-3/</loc><lastmod>2026-06-09T02:18:36+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/contact-2/</loc><lastmod>2026-06-09T02:18:57+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/services-2/</loc><lastmod>2026-06-09T02:20:46+00:00</lastmod></url><url><loc>https://heshmatisolutions.com/contract-2/</loc><lastmod>2026-06-09T02:56:51+00:00</lastmod></url></urlset>
