<?php
include 'config.php'; // your database connection

date_default_timezone_set("Asia/Kolkata");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $email = $_POST['email'];
    $email = mysqli_real_escape_string($con, $email); // prevent SQL injection

    $query = "SELECT `id`, `pid`, `name`, `email`, `password`, `au`, `time_stamp` FROM `users` WHERE email = '$email'";
    $result = mysqli_query($con, $query);

    if (mysqli_num_rows($result) > 0) {
        $timestamp = date("d-m-Y H:i:s");
        $message = "Reset my password for this email ID: $email on $timestamp";
        $encodedMessage = urlencode($message);
        $whatsappNumber = "917043311587"; // include country code (India = 91)
            echo '<script>window.location.href = "https://wa.me/$whatsappNumber?text=$encodedMessage";</script>';
            exit();
    } else {
        echo "Email not found in our records.";
    }
}
?>