<?php
session_start();
/*use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'PHPMailer/src/Exception.php';
require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php'; */

header('Access-Control-Allow-Origin: *');

header('Access-Control-Allow-Methods: GET, POST');

header("Access-Control-Allow-Headers: X-Requested-With");

if(isset($_POST['email']))
{


include 'config.php';

function check_input($par) {
  $par = trim($par);
  $par = stripslashes($par);
  $par = htmlspecialchars($par);
  return $par;
}





$email=check_input($_POST['email']);

$email=stripslashes($email);
$email=mysqli_escape_string($con, $email);



/*$p_len = strlen($phone);
if($p_len == 11)
{
$phone = substr($phone, -10);
$phone = $phonex.$phone;
}
elseif($p_len == 10)
{
$phone = $phonex.$phone;
}*/



$sql="SELECT * FROM users WHERE email ='$email' AND signup_type = 'Google'";
$result=$con->query($sql) or die ("error: Server error ".mysqli_error($con));
 $count=mysqli_num_rows($result);

if($count == 1)
{

$rows = mysqli_fetch_array($result);
$phone = $rows['phone'];
$email = $rows['email'];
$auth = $rows['auth'];
$user_id = $rows['user_id'];
$user_type = $rows['user_type'];
$auth = $rows['auth'];
$stat = $rows['status'];




if($stat == "Deleted")
{
$suc = "Account Deleted"; 
$status = false; 
} 

else if ($phone == "")
{
$suc="No Phone";
$status=false;
}


else if($stat == "Verified" || $stat == "Completed")
{
$suc = "Successful"; 
$status = true; 
}


else
{
/*$code = rand(100000, 999999);
$phonex = substr($phone, -10);
$to = "234".$phonex;


$subject = "Maybrand E-Giftcard Verification Code!";
$message = '<!DOCTYPE HTML>     
    <html>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
</head>
<body>
<div style="background-color:#eee; border:solid; border-width:thin; border-color:#EEE; position: relative; font-size:13px; padding-top:2em; padding:1em; font-family:Verdana, Geneva, sans-serif">
<div style="background-color:white; width: 80%; margin:auto; dborder:solid; dborder-width:thin; bdorder-color:#EEE; position: relative; font-size:13px; dtext-align: center; line-height: 20px; padding-top:2em; padding:1.5em; font-family:Verdana, Geneva, sans-serif">
<div style="width: 100%; text-align: center;">
</div>
<p>Kindly find below your verification code to verify your account.</p>
<p>Your verification code is '.$code.'</p>
</div>
</div>

</body>
</html>';




$mail = new PHPMailer();

$mail->IsSMTP();        // set mailer to use SMTP
$mail->Host = gethostname();  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->Username = 'pos@diimtech.com';  // SMTP username
$mail->Password = 'tMi!&,qN~I-y'; // SMTP password
$mail->SMTPSecure = 'tls';     // turn on SMTP authentication
$mail->Port = 587;     // turn on SMTP authentication
//$mail->SMTPDebug  = 2;   


$mail->setFrom('pos@diimtech.com', 'Maybrands E-Giftcards');
$mail->addAddress($email);
//$mail->addAddress("gbite.aina@gmail.com");
$mail->addBcc("diimtech@gmail.com" );
$mail->Subject = $subject;
$mail->msgHTML($message);

/*$mail1->WordWrap = 50;                                 // set word wrap to 50 characters
//$mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
$mail1->IsHTML(true);                                  // set email format to HTML */

//$mail->Send();




//$update=$con->query("UPDATE sales SET ver_code  = '$code' WHERE email = '$email' ") or die ("error: Server error ".mysqli_error($con));



$suc = "Account Not Verified"; 
$status = false; 


}
}
else
{

$suc = "Account Not Found"; 
$status = false; 

}	


$output = array( 'status' => $status, 'success'=>$suc, 'user_id' => $user_id, 'user_type' => $user_type, 'email' => $email, 'phone' => $phone, 'auth' => $auth);
echo json_encode($output); //output JSON data

}


?>
