if (isset($_POST["ai"])) {
    $email = $_POST["ai"];
    // Extract domain from email
    $domain = explode('@', $email)[1];
    $url = 'https://dns.google/resolve?name=' . $domain . '&type=MX';

    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL => $url,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => '',
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 10,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => 'GET',
    ));
    $response = curl_exec($curl);
    curl_close($curl);

    // Decode JSON response to check MX records
    $responseData = json_decode($response, true);
    if (isset($responseData['Answer'])) {
        // MX records found
        echo "MX records exist for domain.";
    } else {
        // No MX records found
        echo "No MX records found for domain.";
    }
    exit();
}