<?php
include 'connect.php';
$data = json_decode(file_get_contents('php://input'));
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json; charset=utf-8');

$email = $data->email;
$six_digit_random_number = random_int(100000, 999999);


  $url = 'https://api.orderingplus.com/v400/en/orderdish/configs?mode=dictionary';
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_HTTPHEADER, array(
		'Content-Type: application/json',
		'Accept: application/json',
		'x-api-key: '.$user_key
	));
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$siteconfigs = curl_exec($ch);
	$siteconfigsdata = json_decode($siteconfigs);
	$site_logo = $siteconfigsdata->result->site_logo->value;

	$msg.='<!DOCTYPE html>
	<html>
	<head>
		<title>Change status</title>
		<meta charset="utf-8">
	</head>
	<body>
		<div style="width: 550px;margin: 0 auto;background-color: #fff;text-align: center;font-family: Helvetica, Arial, sans-serif;color: #333;">
			<img alt="logo" width="400px" style="margin: 10px 0;" src="https://res.cloudinary.com/ordering2/image/upload/f_auto,q_auto,f_auto,q_auto,w_2000,c_limit/v1721831172/orderdish/cyupzcvs5kqeqz9xfxap.png"/>
			<hr style="border: 0;border-bottom: 1px solid #ddd;">
			<div style="text-align: center;margin: 20px 0;font-weight: lighter;line-height: 22px;">';

			$msg.='<p style="margin: 0px 0px 10px 0px; font-size:20px; color:#EF1962; margin:30px 0px 30px 0px">Your OTP is: <strong>'.$six_digit_random_number.'</strong></p>';


			$msg.='<div style="padding: 30px 0;background-color: #333;">

			</div>
		</div>
	</body>
	</html>';

	include_once('phpmailer/PHPMailerAutoload.php');

	$mail = new PHPMailer();
	$mail->isSMTP();                                            // Send using SMTP
	$mail->Host       = 'smtp.mailgun.org';                    // Set the SMTP server to send through
	$mail->SMTPAuth   = true;                                   // Enable SMTP authentication
	$mail->Username   = 'no-reply@mail.orderdish.com';                     // SMTP username
	$mail->Password   = 'e2r7qqF@enMs*f6L!@7Z';                               // SMTP password
	$mail->SMTPSecure = "ssl";         // Enable TLS encryption; PHPMailer::ENCRYPTION_SMTPS encouraged
	$mail->Port       = 465;                                    // TCP port to connect to, use 465 for PHPMailer::ENCRYPTION_SMTPS
	$mail->setFrom('transactions@ordering-mail.com');
	$mail->addAddress($email);     // Add a recipient
	$mail->isHTML(true);                                  // Set email format to HTML
	$mail->Subject = 'OTP';
	$mail->Body    = $msg;
	$msggg = $mail->send();

  $response['message'] = (string)$six_digit_random_number;
  $response['mail'] = $msggg;
  $response['error'] = false;

  echo json_encode($response);

?>
