You are on page 1of 1

<!

DOCTYPE html>
<html>
<head>
<title>Recover Password</title>
</head>
<body>
<h1>Recover Password</h1>
<form action="send_recovery_code.php" method="post">
<label for="email">Email Address:</label><br>
<input type="email" id="email" name="email" required><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

<?php
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve the email address from the form
$email = $_POST["email"];

// Generate a random recovery code


$recovery_code = mt_rand(100000, 999999);

// Send the recovery code to the email address


$to = $email;
$subject = "Password Recovery Code";
$message = "Your recovery code is: " . $recovery_code;
$headers = "From: your_email@example.com";

if (mail($to, $subject, $message, $headers)) {


echo "Recovery code sent successfully. Check your email.";
} else {
echo "Failed to send recovery code. Please try again later.";
}
}
?>

You might also like