<?php
session_start();
include "../../config/db.php";
include "../../config/config.php";

$msg = "";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;



if ($_SERVER["REQUEST_METHOD"] == "POST") {
 
  if (empty($_POST["email"])) {
    $msg = "Email is required";
  } else {
    $email = test_input($_POST["email"]);
    
    }
  	
	$email = $link->real_escape_string($_POST['email']);
	
	
	if($email == "" ){
		$msg = "email fields cannot be empty!";
		
	}else {
   

					$sql = "SELECT * FROM users WHERE email = '$email' ";

          $result = mysqli_query($link, $sql);
          if(mysqli_num_rows($result) == 1){
             $row = mysqli_fetch_assoc($result);
            $id = $row['id'];
            

           
            
		  require_once "PHPMailer/PHPMailer.php";
          require_once 'PHPMailer/Exception.php';


//PHPMailer Object
$mail = new PHPMailer;

//From email address and name
     $mail->setFrom($emaila);
   $mail->FromName = $name;

//To address and name
$mail->addAddress($email);


//Address to which recipient will reply

//Send HTML or Plain Text email
$mail->isHTML(true);

$mail->Subject = "Password Reset";
$mail->Body ='
              
              
<div class="be_container" style="background: #220a80; width: 100%; height: 100%; font-family: sans-serif; font-weight: 100;">
<div class="be_inner_containr" style="background: #220a80; max-width: 600px; margin: 0px auto; padding: 30px;">
<div class="be_header">
<p><img style="display: block; margin-left: auto; margin-right: auto;" src="https://bumainc.manorpa.com/buma/img/logo/logo3.png" /></p>
<p>&nbsp;</p>
<div style="clear: both;">&nbsp;</div>
<div class="be_bluebar" style="background: #220a80; padding: 20px; color: #fff; margin-top: 10px;">
<h1>Thank you for investing on '.$name.'</h1>
</div>
</div>
<div class="be_body" style="padding: 20px;">
<p><strong><span style="color: #ffffff;">Click on the link below to Reset your password</span></strong></p>
<p style="line-height: 25px;"><strong><span style="color: #ffffff;"><a style="color: #ffffff;"href="https://bumainc.manorpa.com/buma/users/form/confirmres.php?id='.$id.'&amp;email='.$email.'
">Click here to reset password</a></span></strong></p>
<div class="be_footer">
<div style="border-bottom: 1px solid #ccc;">&nbsp;</div>
<div class="be_bluebar" style="background: #220a80; padding: 20px; color: #fff; margin-top: 10px;">
<p>Please do not reply to this email. Emails sent to this address will not be answered.</p>
<p>&nbsp;</p>
<p style="text-align: center;">Copyright 2023 '.$name.'.</p>
<div class="be_logo" style="width: 60px; height: 40px; float: right;">&nbsp;</div>
</div>
</div>
</div>
</div>
</div>
</div>   
              
              
              ';

if(!$mail->send()) 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
} 
else 
{
    $msg =  "Check Your Email and follow the link to reset your password";
}
               
            } else{
                echo "Something went wrong. Please try again later.";
            }
        }
         
				 
		
		
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}


?>



<!DOCTYPE html>
<html lang="zxx">
<head>
<title>Buma Investment</title>

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<link href="css/bootstrap.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/snow.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/component.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/style_grid.css" rel="stylesheet" type="text/css" media="all" />
<link href="css/style.css" rel="stylesheet" type="text/css" media="all" />
<!-- font-awesome-icons -->
<link href="css/font-awesome.css" rel="stylesheet"> 
<!-- //font-awesome-icons -->
<link href="//fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i,800" rel="stylesheet">
</head>

<style>
#inp{
   border-radius:5px; 
    background-color:#fff;
}    
 #den{
        border-radius:5px; 
     background-color:#8ca2bf;
     color:green;
     margin-top:100px;
 } 

</style>
<body>
			

						<div class="">
							<!-- /login -->
							   <div class="">
								    <div class="registration">
								
												<div id="den" class="signin-form profile">
												<p><a title="BACK TO HOMEPAGE" href="https://www.bumainc.com/"><img src="https://bumainc.manorpa.com/buma/img/logo/logo3.png" /></a></p>
													<h2 style="color:#fff;font-family:Comic Sans MS;">Password Reset</h2>

													<?php if($msg != "") echo "<div style='padding:20px;background-color:#dce8f7;color:black'> $msg</div class='btn btn-success'>" ."</br></br>";  ?>

													<div class="login-form">
														<form  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">

														
															
															
																<input placeholder="Enter your email" id="inp" type="email" name="email" >
                                                                <span class="help-block"><?php echo $email_err; ?></span>
                                                               
															   
															
																
																
							</br>
															<div class="tp">
																<input type="submit" name="submit" value="Reset">
															</div>
														</form>
													</div>
													
																						 <h6>Back to login &nbsp; <a href="signin.php"> LOGIN</a><h6>
												</div>
										</div>
										<!--copy rights start here-->
											<div class="copyrights_agile">
											<p>© 2023 <?php echo $name;?>. All Rights Reserved</a> </p>
											</div>	
										
						    </div>
						</div>


<!-- js -->

          <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
		  <script src="js/modernizr.custom.js"></script>
		
		   <script src="js/classie.js"></script>
		 <script type="text/javascript" src="js/bootstrap-3.1.1.min.js"></script>


</body>
</html>