<?php 

$dir = '../';

require_once $dir.'includes/main.php';

$errors = array();

$email = clean($_POST['email']);

// check email
$sql = "SELECT * FROM users WHERE email = '{$email}' LIMIT 1";
if(fetch_rows($sql) < 1){

   ex_messages(['The email address you entered are incorrect. Please try again']);

}else{

   $new_pass = rand(1000000, 10000000);

   $message = "<p>Dear user,</p>";
   $message .= "<p>Here is your new password: " . $new_pass . "<p>";
   $message .= "<p>Thank you,<br />";
   $message .= $set['website_name']."<p>";

   if(email_user($email, 'Password Reset', $message)){

      $new_pass = sha1($new_pass);

      query("UPDATE users SET password = '{$new_pass}' WHERE email = '{$email}' LIMIT 1");

      ex_messages(['An email has been sent to you']);

   }else{

      ex_messages(['Could not send the email. Please try again or contact support']);

   }

}

?>