<?php

require 'includes/dbconnect.php';
session_start();

$success = false;
$exist = false;

$string = '0123456789';
//$string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$string_shuffled = str_shuffle($string);
$pass = substr($string_shuffled, 1, 4);

$from = $_REQUEST['from'];

$_SESSION["otpuser"] = $pass;


if (isset($_REQUEST["mobile"])) {
    $mobile = $_REQUEST['mobile'];
    $mobnum = $mobile;

    $msgtech = 'Your Mobile Number Verification OTP Is' . " " . $pass . " ";

    $user = "tamboli2013";
    $password = "tamboli2013";
    $senderid = "TMBOLI";
    $url = "http://vas.mobilogi.com/api.php";



    $mobilenumbers = $mobnum;

    $messagetech = urlencode($msgtech);

    $chtech = curl_init();
    if (!$chtech) {
        die("Couldn't initialize a cURL handle");
    }
    $rettech = curl_setopt($chtech, CURLOPT_URL, $url);
    curl_setopt($chtech, CURLOPT_POST, 1);
    curl_setopt($chtech, CURLOPT_POSTFIELDS, "username=$user&password=$password&route=1&sender=$senderid&mobile[]=$mobilenumbers&message[]=$messagetech");

    $rettech = curl_setopt($chtech, CURLOPT_RETURNTRANSFER, true);

    $curlresponsetech = curl_exec($chtech);
    if (curl_errno($chtech)) {
//        echo 'curl error : ' . curl_error($chtech);
    }
    if (empty($rettech)) {

        die(curl_error($chtech));
        curl_close($chtech);
    } else {
        $infotech = curl_getinfo($chtech);
        curl_close($chtech);

        $success = true;
    }
}
if (isset($_REQUEST["email"])) {
    $email = $_REQUEST['email'];
//    echo $email;
    $to = $email;



    $subject = "Email Verification From Tamboli Tours N Travels";

    $headers = "From: info@tamboligroups.com\r\n";
//            $headers = "From: bsufiyan79@gmail.com\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    $message = "<html>";
    $message .= "<body>";
    $message .= "<h1 style='color:red;'><b>$ordermail</b></h1>";
    $message .= "<table>";
    $message .= "<tr>";
    $message .= "<td>Your Email Verification OTP is <b>$pass</b></td>";
    $message .= "</tr>";
    $message .= "</table>";
    $message .= "</body>";
    $message .= "</html>";


    mail($to, $subject, $message, $headers);
    $success = true;
}

$rows = array('success' => $success,'otp'=>$pass);
header("Content-type: application\json");
echo json_encode($rows);
