<?php
if (isset($_POST['submitted'])) {
    //require_once('mysqli_connect.php');

    error_reporting(E_ALL);
	ini_set('display_errors', '1');
        
    $errors=array();
   	// Connect to MySQL
	//$c = mysql_connect("localhost", "root", "");
	//mysql_select_db("main", $c);
	require_once('mysqli_connect.php');
	// Was the form submitted?
	if (isset($_POST['submitted'])) {
	
    if (empty($_POST['emailuser'])) {
        $errors[] = 'Ξεχάσατε το e-mail σας.';
    } else {
        $email = mysqli_real_escape_string($dbc, trim($_POST['emailuser']));
    }
        
	    // Harvest submitted e-mail address
	    //$email = mysqli_real_escape_string($dbc, trim($_POST['email']));
	 
	    // Check to see if a user exists with this e-mail
        }
        
    if (!empty($errors)) {
        
    } else {
  //  include 'login2.html';
            $qq="SELECT email FROM users WHERE email='$email'";
            $r=mysqli_query($dbc, $qq);
            $userExists = mysqli_fetch_array($r, MYSQLI_ASSOC);
	    
	    if ($userExists['email'])  {
	    
	                // Create a unique salt. This will never leave PHP unencrypted.
	                $salt = "PiuwrO1#O0rl@+luH1!froe*l?8oEb!iu)_1Xaspi*(sw(^&.laBr~u3i!c?es-l651";

  
	        // Create the unique user password reset key
	        $password = SHA1($salt . $userExists['email']);

	        // Create a url which we will direct them to reset their password
	        $pwrurl = 'reset_pass.php?q=' . $password;
	 
       //                      'To: fotkon9707@yahoo.com' . "\r\n" .   
     //               'Reply-To: fotkon9707@yahoo.com' . "\r\n" .
   // 'X-Mailer: PHP/' . phpversion();
   //  "From: fotkon97@yahoo.com\r\n"
	        // Mail them their key
      
                $mailbody = "Dear user,\n you have requested a password reset\n\n"
                        . " please click the link below\n\n"
                        . " or paste it into your web browser.\n\n localhost/eStratopedo/login/" . $pwrurl . "\n\n";
                $subject=' Password Reset';
                $email_from='sphyptyxiaki@gmail.com';
 //               ini_set('sendmail_from', $email_from);
//                ini_set("sendmail_to", $email);
                $headers = 'From: '.$email_from;

        

	        mail($email, $subject, $mailbody,$headers);
        echo ' <div id="login" class="animate form"><h1>Your password recovery key has been sent to your e-mail address:'.$email.'"</h1>'
                . ' <a href="login.php"> Go back to login page</a></div>';

	    }
	    else
	        echo '<div id="login" class="animate form"><h1>No user with that e-mail address exists.</h1></div>';

}

include 'indexf.php';


            } else{
            include 'indexf.php';
            }
            ?>
            