<?php 
require_once 'config.php';
$error=false;
$errors=array();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
   
  
   $user_id=$_POST['user_id'];
   $banner_id=$_POST['banner_id'];
   
 
	
		$createCustomer=mysqli_query($con,"INSERT INTO grab_offer (user_id,banner_id,date) VALUES(".$user_id.",'".$banner_id."','".date('Y-m-d H:i:s')."')");
		
		if($createCustomer){
			
			$promotions=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM promotions WHERE id=".$banner_id));	
			$touser=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM users where id=".$promotions['user_id']));
	   $sql12="SELECT * FROM users where id=".$user_id;	   
		$users=mysqli_fetch_array(mysqli_query($con,$sql12));
		

			$to = $touser['email'];
			$subject = "An Offer has been grabed by ".$users['first_name']."(".$users['email'].")";
			$txt = "An Offer has been grabed by ".$users['first_name']."(".$users['email'].")Phone: ".$users['phone']. "\r\n";
			$headers = "From: noreply@trendinfotechs.com" . "\r\n" ;

			mail($to,$subject,$txt,$headers);
			$errors['success']=true;						
			
			
			
			$errors['message']='Offer Grabed successfully.';
		}else{
			$error=true;
			$errors['error']='Something went wrong!!!, Please try again.';
		}
	
 	 
	 	echo json_encode($errors);
}