<?php
include '../db.php';
$today = date('Y-m-d');
$target = date('Y-m-d', strtotime('+30 days'));

$stmt = $conn->query("
    SELECT d.*, c.name, c.email, c.phone 
    FROM domains d 
    JOIN clients c ON d.client_id = c.id 
    WHERE expiry_date BETWEEN '$today' AND '$target'
");

$expiring = $stmt->fetchAll();

foreach ($expiring as $d) {
    // EMAIL reminder
    $to = $d['email'];
    $subject = "Domain Expiry Reminder: {$d['domain_name']}";
    $message = "Dear {$d['name']}, your domain {$d['domain_name']} will expire on {$d['expiry_date']}. Please renew soon.";
    $headers = "From: admin@yourdomain.com";

    mail($to, $subject, $message, $headers);

    // WhatsApp (via API, e.g., Gupshup, Twilio etc.)
    // You can integrate using CURL/post API here
}
?>
