<?php
include '../db.php';

$today = date('Y-m-d');
$target = date('Y-m-d', strtotime('+30 days'));

$stmt = $conn->query("
    SELECT h.*, c.name, c.email, c.phone 
    FROM hostings h 
    JOIN clients c ON h.client_id = c.id 
    WHERE expiry_date BETWEEN '$today' AND '$target'
");

$expiring = $stmt->fetchAll();

foreach ($expiring as $h) {
    // Email reminder
    $to = $h['email'];
    $subject = "Hosting Expiry Reminder: {$h['plan']}";
    $message = "Dear {$h['name']}, your hosting plan '{$h['plan']}' will expire on {$h['expiry_date']}. Please renew soon.";
    $headers = "From: admin@yourdomain.com";

    mail($to, $subject, $message, $headers);

    // WhatsApp reminder (integrate your API here)
}
?>
