<?php session_start(); 
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../PHPMailer/Exception.php';
require '../PHPMailer/PHPMailer.php';
require '../PHPMailer/SMTP.php';
include("db_config.php"); 
if($_SERVER['REQUEST_METHOD']=='POST'){	
	//var_dump($_POST);
    $logo = "http://orangegroceries.com/img/logo.png";
    $logo_width = "100%";
    $logo_height = "";
    // All CSS
    // Body
    $body_title = "Orange Groceries";
    $width_of_mail_body = "80%"; // Please write in % percentage for better view...
    $padding_of_mail_body = "20px";
    $body_background_color = "";
    $body_text_color = "";
    // Header
    $header_background_color = "";
    $header_text_color = "";
    $header_font_size = "";
    $header_font_family = "";
    // Footer
    $footer_background_color = "#2F3B59";
    $footer_text_color = "white";
    $footer_font_size = "10px";
    $footer_font_family = "monospace";
    // Button
    $button_background_color = "#4db7fe";
    $button_text_color = "white";
    $button_font_size = "20px";
    $button_font_family = "monospace";
    $button_padding = "15px";
    $button_border_radius = "10px";
    // Highlight
    $highlight_color = "#4db7fe";
    $highlight_font_size = "25px";
    $highlight_font_family = "monospace";
    // Heading
    $heading_color = "#4db7fe";
    $heading_font_size = "25px";
    $heading_font_family = "monospace";

	$mobile_no = $_POST['mobile_no'];
	$email = $_POST['email'];
	$name = $_POST['name'];
	$password = $_POST['password'];
	$sql = "SELECT count(*) as num FROM user_profile WHERE email = '$email'";
	$result = mysqli_query($conn, $sql) or die(mysqli_error($conn));
	$res= mysqli_fetch_array($result);
    //$count=mysqli_num_rows($result);
    $count=$res['num']; 
    if($count > 0 )
    { 
		$response['status']=1;
	}else{
        date_default_timezone_set('Asia/Kolkata');
       $date = date('Y-m-d H:i:s');
		$sql1 = "INSERT INTO user_profile(email,fname,mob_no,password,created_date) values ('$email','$name','$mobile_no','$password','$date')";
		$result1 = mysqli_query($conn, $sql1) or die(mysqli_error($conn));
		 $last_id= mysqli_insert_id($conn);
		 $sqll ="SELECT * FROM user_profile WHERE id = '".$last_id."'";
$resultt = mysqli_query($conn, $sqll) or die(mysqli_error($conn));
$ress= mysqli_fetch_array($resultt);
$name=$ress['fname'];
$email=$ress['email'];
$date = date("d-m-Y");
    $from_team = "Orange Groceries";
    $from_website = "http://orangegroceries.com/index.php";
    $to = $email;
    $message = "
                <html>
                    <head>
                        <title>$body_title</title>
                    </head>
                    <body style='background-color: $body_background_color; color: $body_text_color;'>
                        <center>
                            <div style='width: $width_of_mail_body; padding: $padding_of_mail_body;' >
                                <br/><br/>
                                <p style='color: $paragraph_color; font-size: $paragraph_font_size; font-family: $paragraph_font_family;'> 
                                    <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'>
                                        Hi $name,
                                    </span> 
                                    <br/>
                                    Welcome to <span style='color: $highlight_color; font-size: $highlight_font_size; font-family: $highlight_font_family;'> $from_team</span>, Your Registration Completed , Shop With Exciting Offer With Orange Groceries <br/> Thankyou!!!
                                </p>
                                <br/><br/><br/><br/>
                                <div style='width: 100%; background-color: $footer_background_color; color: $footer_text_color; font-family: $footer_font_family; font-size: $footer_font_size; padding-top: 30px; padding-bottom: 30px;'>
                                    Thanks And Regards
                                    <br/>
                                    <span style='color: white;'>$from_website</span>
                                </div>
                            </div>
                        </center>
                    </body>
                </html>";


$email = new PHPMailer();
$email->Body      =  ($message);
$email->SetFrom('support@orangegroceries.com', 'Orange Groceries'); //Name is optional
$email->Subject   = $name . "Your Registration successfully Completed";
$email->IsHTML(true);
$email->Body      =  ($message);
$email->AddAddress($t);
   if (! $email->Send()) {
       //echo "<script>alert('Problem in sending email!');</script>";
    } else {
    }
		$response['user_id']=$last_id;
        $response['status']=2;
	}
	
	echo json_encode($response);
	mysqli_close($conn);
}
	
