<?php 
ob_start();
session_start();
ini_set("display_errors", 0);

require_once("config.php");
$session_id = session_id();

// 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
$sqlExists = "SELECT * FROM `og_users` WHERE `email` = '".$_POST['remail']."'";
$exeExists = mysqli_query($connection,$sqlExists);
$numExists = mysqli_num_rows($exeExists);
if($numExists==0)
{
	$sqlInsert = "INSERT INTO `og_users` SET `fname` = '".addslashes($_POST['rfname'])."',`lname` = '".addslashes($_POST['rlname'])."',`email` = '".addslashes($_POST['remail'])."',`password` = '".md5($_POST['rpassword'])."',`original_password` = '".$_POST['rpassword']."',`phone` = '".addslashes($_POST['rphone'])."',`registration_date` = '".date('Y-m-d H:i:s',time())."',`is_active` = 'No'";
	$exeInsert = mysqli_query($connection,$sqlInsert);
	$last_id = mysqli_insert_id($connection);
	
	//SEND EMAIL TO USER
    $name = 'Flaro Deals';
    $emaila = $_POST['remail'];

	$email_account = "info@prismonline.in";
    $email_password = "~I5er1FU&bR0";

	// Recipient
	$mail = new PHPMailer;
	$mail->isSMTP();
	$mail->SMTPDebug = 0;
	
	$subject = 'Registration Successful';	
	$message = '<table border="0" width="100%" cellspacing="2" cellpadding="2">
				<tr>
					<td>Dear '.stripslashes($_POST['rfname']).' '.stripslashes($_POST['rlname']).',</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<td>Thanks for your registration. Please click the link below to activate your account.<br>
					<a href="'.SITE_URL.'activate.php?user_id='.$last_id.'">'.SITE_URL.'activate.php?user_id='.$last_id.'</a></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
				</tr>				
				<tr>
					<td>Thanks & Regards,<br>Flaro Deals 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', "Flaro Deals");
	$mail->addReplyTo('info@prismonline.in', "");
	$mail->addAddress($emaila);
	$mail->Subject = $subject;
	$TemplateMessage = $message;
	$mail->MsgHTML($TemplateMessage);
	$mail->send();
	
	$sql_update = "UPDATE `og_temp_cart` SET `user_id` = '".$last_id."' WHERE `unique_id` = '".$session_id."'";
	$exe_update = mysqli_query($connection,$sql_update);

	echo 'succ';
}
else
{
	echo 'fail';
}
?>