<?php 
require_once("header.php");

// Stop making changes below this line
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'phpmailer/PHPMailer-master/src/Exception.php';
require 'phpmailer/PHPMailer-master/src/PHPMailer.php';
require 'phpmailer/PHPMailer-master/src/SMTP.php';
?>

<?php
if(isset($_POST['send']))
{
    $sqlForgot = "SELECT * FROM `pd_brokers` WHERE `email` = '".$_POST['femail']."'";
    $exeForgot = mysqli_query($connection,$sqlForgot);
    $numForgot = mysqli_num_rows($exeForgot);
    if($numForgot>0)
    {
    	$arrForgot = mysqli_fetch_array($exeForgot);
    	
    	$name8 = stripslashes($arrForgot['fname'])." ".stripslashes($arrForgot['lname']); 
	    $email8 = stripslashes($arrForgot['email']);
        $broker_code = stripslashes($arrForgot['broker_code']);
        
    	//SEND EMAIL TO USER
    	$email_account = "info@prismonline.in";
        $email_password = "~I5er1FU&bR0";
    
    	// Recipient
    	$mail = new PHPMailer;
    	$mail->isSMTP();
    	$mail->SMTPDebug = 0;

    	$subject = 'Forgot Code';	
    	$message = '<table border="0" width="100%" cellspacing="2" cellpadding="2">
    				<tr>
    					<td>Dear '.$name8.',</td>
    				</tr>
    				<tr>
        			    <td>&nbsp;</td>
            		</tr>
            		<tr>
            			<td>We are sorry that you misplaced your code, but not to worry. Your code is <b>'.$broker_code.'</b> Please keep this code secret and do not share with others. It is also your login ID.</td>
            		</tr>
            		<tr>
            			<td>&nbsp;</td>
            		</tr>
            		<tr>
            			<td>Thanks & Regards,<br>Properti Dost Team</td>
            		</tr>
    				</table>';

    	$mail->Host = 'mail.prismonline.in';
    	$mail->Port = 587;
    	$mail->SMTPAuth = true;
    	$mail->SMTPSecure = "tls";
    	$mail->Username = $email_account;
    	$mail->Password = $email_password;
    
    	$mail->setFrom('info@prismonline.in', "Properti Dost");
    	$mail->addReplyTo('info@prismonline.in', "");
    	$mail->addAddress($email8);
    	$mail->Subject = $subject;
    	$TemplateMessage = $message;
    	$mail->MsgHTML($TemplateMessage);
    	$mail->send();
    	
    	$_SESSION['msg_succ'] = 'Your code has been sent to your mailbox.';
		header("location: forgot-code.php");
		exit;
    	
    }
    else
    {
        $_SESSION['msg_fail'] = 'Email not found. Please try again!';
    	header("location: forgot-password.php");
    	exit;
    }
}
?>

            <!-- page template area start -->
			<section id="about">
				<div class="container mt-10 pb-10 pt-0">
					<div class="row">
						<div class="col-md-5">
							<div class="">
								<?php require_once("left_panel.php");?>
							</div>
						</div>
						<div class="col-md-7">
							<h1 class="title mt-5 mb-15" style="text-align:left;">Forgot Code</h1> 
							<?php if(isset($_SESSION['msg_fail'])) { ?>
							<p class="text-left"><img src="images/cross.png" alt="" /> <?php echo $_SESSION['msg_fail'];?></p>
							<?php 
							unset($_SESSION['msg_fail']);
							} 
							?>
							<?php if(isset($_SESSION['msg_succ'])) { ?>
							<p class="text-left"><img src="images/tick.png" alt="" /> <?php echo $_SESSION['msg_succ'];?></p>
							<?php 
							unset($_SESSION['msg_succ']);
							} 
							?>
							<form id="contact_form" name="contact_form" class="" action="" method="post" onSubmit="return form_validation();">
							<div class="row">
								<div class="col-sm-12">
									<div class="form-group">
										<input name="femail" id="femail" class="form-control" type="text" placeholder="Enter Email Address *" value="">
									</div>
								</div>
							</div>
							<div class="form-group">
								<input type="hidden" name="send" id="send" value="1" />
								<button type="submit" class="btn btn-flat btn-theme-colored border-left-theme-color-2-4px">Submit</button>
							</div>
							</form>
							<p><a href="broker-login.php" style="color:#e53935">Back To Brokerdost Login</a></p>
						</div>
					</div>
				</div>
			</section>
			<!-- page template area end -->
			
<?php require_once("footer.php");?>