<?php

include('../config.php');   


	function mail_calling($email,$pwd)
	{  
		 
		$link =  ROOTPATH.'/login/reset_pwd.php?email='.$pwd; 
        $Ticket_data =  "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
		<html xmlns='http://www.w3.org/1999/xhtml'>
		<head>
		<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
		<title>Newsletter</title>
		</head>
		<body>
		<div style='width:600px; margin:0px auto; border:1px solid #ddd; background:#f9f9f9; font-family:Arial, Helvetica, sans-serif; font-size:16px; color:#444; '>
		<table width='100%' border='0' cellspacing='0' cellpadding='0'>
		<tr>
		<td height='150' align='center' valign='middle' bgcolor='#FFFFFF'><img  src='".MAIN_ROOTPATH."/uploads/mail-images/banner.png' alt='img' /></td>
		</tr>
		<tr>
		<td style='background:url('".MAIN_ROOTPATH."/uploads/mail-images/shadow.png) repeat-x left top;'>&nbsp;</td>
		</tr>
		<tr>
		
		<td>
		
		<div style=' display:block;padding:1px 20px 15px; color:#333; font-size:19px; line-height:28px ; text-align:left;'>Hello ".$name.",<br />
		<span style='color:#e90021;'>Congratulations! </span>You have successfully reset password
		</div>
		
		
		<div style=' display:block;padding:1px 20px 15px; color:#333; font-size:16px; line-height:28px ; text-align:left;'> 
		   <a href=".$link."> <span style='color:#e90021;'> Please click on this link to reset your password </span> </a>
		</div>
		
		
		</td>
		</tr>   
		<tr>
		<td bgcolor='#f3f3f3'>
		<div style='padding:20px; display:block;'>
		<div style='width:20%; text-align:center; float:left; display:inline-block; padding-bottom:20px;'>
		<img  src='".MAIN_ROOTPATH."/uploads/mail-images/alert.png' width='49' height='43' alt='img' />
		</div>
		<div style='width:79%; float:right; text-transform:uppercase; display:inline-block; font-weight:bold; color:#333; font-size:15px;'>
		Beware of fraud Agents!
		Do not pay money before priore knowledge!
		</div>
		<div style='clear:both'></div>
		<p style=' border-top:1px dotted #b9b9b9; margin:0px; padding-top:17px; font-size:13px; color:#666;'>
		<a href='http://www.vastusarthi.com' style='color:#008acc'>Vastu sarthi</a> is the fastest growing site in india , get quick and guaranteed response. Become paid member and enjoy more response from Vastusarthi.
		</p>
		</div>
		</td>
		</tr>  
		</table> 
		</div> 
		</body>
		</html>  
		"; 
 
		$to = $pwd;
		$from = "info@vastusarthi.com";
		$subject = "Thanks for reset password";    
		$message = Ticket_data;    
		$headers  = "From: $from\r\n";
		$headers .= "Content-type: text/html\r\n";    
		mail($to, $subject, $message, $headers);   
	}
	
	 
	
	 if(isset($_POST['submit']))
	 {
		$email=$_POST['email'];
	   	$pwd=rand(2344,45);		
	    
		try
	   {
	   	 	
         $stmt=$conn->prepare("select * from  registration where email=:email");
	   	 $stmt->bindValue(':email', $_POST['email'], PDO::PARAM_STR); 	   	  
		 $stmt->execute();   
		 $affected_rows = $stmt->rowCount();     
		 
		 if($affected_rows > 0)	
		 {			
		   $stmt=$conn->prepare("update registration set pwd=:pwd where email=:email");
	   	   $stmt->execute(array(':email'=>$email,':pwd'=>$pwd));
	   	   echo '<script type="text/javascript">alert("Your Password has been reset Successfully!!! Kindly check your email id to reset password!!")</script>'; 
		   mail_calling($email,$pwd);         		 
	     }
		else
		{
			echo '<script type="text/javascript">alert("Email Id Does Not Exits!!")</script>'; 
		}
	   }
	   catch(PDOException $e)
      {
        echo $e->getMessage();		
      }
	  
	 } 
	
	$filename = basename(__FILE__); 
	include_once("../view/login/".$filename); 
?>