prepare('SELECT id, name FROM users WHERE email = ?'); $stmt->execute([$email]); $user = $stmt->fetch(); if ($user) { $token = bin2hex(random_bytes(32)); $expiry = date('Y-m-d H:i:s', strtotime('+1 hour')); $update = db()->prepare('UPDATE users SET reset_token = ?, reset_expires_at = ? WHERE id = ?'); $update->execute([$token, $expiry, $user['id']]); $host = $_SERVER['HTTP_HOST'] ?? 'localhost'; $protocol = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') ? 'https' : 'http'; $reset_link = "$protocol://$host/reset-password.php?token=$token"; $subject = 'Reset Your Password'; $name = htmlspecialchars($user['name'] ?? 'User'); $html = "

Password Reset Request

Hello $name,

You recently requested to reset your password for your $project_name account. Click the button below to reset it. This link is valid for 1 hour.

Reset Password

If you did not request a password reset, please ignore this email or contact support if you have concerns.


© " . date('Y') . " $project_name. All rights reserved.

"; $text = "Hello $name,\n\nYou recently requested to reset your password for your $project_name account. Copy and paste the link below into your browser to reset it. This link is valid for 1 hour.\n\n$reset_link\n\nIf you did not request a password reset, please ignore this email."; $res = MailService::sendMail($email, $subject, $html, $text); if (!empty($res['success'])) { $success = 'If an account exists for that email, you will receive a password reset link shortly.'; } else { $error = 'Failed to send the reset email. Please try again later.'; } } else { // For security, don't reveal if the email exists or not $success = 'If an account exists for that email, you will receive a password reset link shortly.'; } } } ?> Forgot Password — <?php echo htmlspecialchars($project_name); ?>

Reset Password

Enter your email and we'll send you a reset link.

Remembered your password? Sign In