<?php
require ("../connection.php");
session_start();
  if (isset($_SESSION['user'])) {
      //header('Location:../login/lockscreen.php'); 
    }
			$user_name=$_REQUEST['user_name'];
			$email_id=$_REQUEST['email_id'];
			$usermaster=mysqli_query($con,"select email_id from user_master where user_name='$user_name' and email_id='$email_id'");
			//echo "select email_id from user_master where user_name='$user_name' and email_id='$email_id'";
			$ucount=mysqli_num_rows($usermaster);
			
			
			if($ucount!=0)
			{
			     $user=mysqli_fetch_array($usermaster);
				 $email=$user['email_id'];
				if($email==$email_id)
				{
					$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
					$pass = array(); //remember to declare $pass as an array
					$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
					for ($i = 0; $i < 10; $i++) 
					{
						$n = rand(0, $alphaLength);
						$pass[] = $alphabet[$n];
					}
					$auto=implode($pass); //turn the array into a string
					$automd5=md5 ($auto);
	
					$up=mysqli_query($con,"update user_master set password='$automd5' where user_name='$user_name'");
												
date_default_timezone_set('Etc/UTC');
require 'phpmailer/PHPMailerAutoload.php';
//Create a new PHPMailer instance
//$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
//$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
//$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
//$mail->Debugoutput = 'html';
//Set the hostname of the mail server
//$mail->Host = "smail.sys.toshiba.co.jp";
//Set the SMTP port number - likely to be 25, 465 or 587
//$mail->Port = 25;
//Whether to use SMTP authentication
//$mail->SMTPAuth = false;

$mail = new PHPMailer;
//$mail->SMTPDebug = 3;                               // Enable verbose debug output
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.zoho.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
//$mail->Username = $from_mail;                 // SMTP username
$mail->Username = 'dinesh.vm@bluebase.in';                 // SMTP username
$mail->Password = 'Dinesh@2494';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to
$mail->Debugoutput = 'html';
$mail->isHTML(true); 


//$mail->SMTPDebug = false;
//Set who the message is to be sent from
$mail->setFrom('dinesh.vm@bluebase.in');
//$mail->setFrom('vikraman@bluebase.in');
//Set an alternative reply-to address
//$mail->addReplyTo('maruthu.u@bluebase.in');
//Set who the message is to be sent to
$mail->addAddress($email_id);
//$mail->addAddress('ravi@bluebase.in');
$mail->addCC($ccmail);
//$mail->addCC('laxmipriya@bluebase.in');
$mail->isHTML(true);
//Set the subject line
$mail->Subject = 'New Password';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->Body    = '<h1>Your New Password Is :</h1><b>'.$auto.'</b><br>
<br>
 Using the above password to login and Change this Password 
<br><br><br>Regrads,<br><br>Admin,<br><br><br>';
//$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) 
{
    //echo "Mailer Error: " . $mail->ErrorInfo;
}
 else 
{
    echo "Message sent!";
}
					echo "Your User Name and Password has been send to your registered Email Id.";
					header('Location:forgotpassword.php?s=1');
				}
				else
				{
					echo "Invalid Email Id";
					header('Location:forgotpassword.php?p=1');
				}
			}
			else
			{
			echo "User Doesnot exists";
			header('Location:forgotpassword.php?u=1');
			}		
				 
		
?>
	
	

	
	
	
	
	