<?php 

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;


if ($_SERVER["REQUEST_METHOD"]=="POST") {

	include_once './config.php';
	require '../PHPMailer/Exception.php';
	require '../PHPMailer/PHPMailer.php';
	require '../PHPMailer/SMTP.php';
	$mail = new PHPMailer(true);
	$objCon = new Config();
	
	
	$validacion["form-availability-guests"] 			    	= array("etiqueta" =>"name", 		"validacion" => "numeros", 	"obligatorio" => "1");
	$validacion["form-availability-email"] 				= array("etiqueta" =>"email", 	"validacion" => "email", 		"obligatorio" => "1");



	$validar = $objCon->clean_and_validate($validacion, $_POST);
	$errors = $validar["errors"];
	$limpios = $validar["data_ok"];


	if (count($errors)==0 && isset($_POST['save'])&& $_POST['save']=="ok") {
		$fechaActual = date('Y-m-d');

		$datos["numpersona"]	= $limpios['form-availability-guests'];
		$datos["correo"] 		= $limpios['form-availability-email'];	
		$datos["fecha"] 		= $fechaActual;

		$info = "";
		foreach ($datos as $key => $value) {
			  $info .= "<br> <strong>".ucwords($key)."</strong>: ".$value;
		}
		 try {
			  //Server settings
			  $mail->SMTPDebug = 0;                      
			  $mail->isSMTP();                                           
			  $mail->Host       = 'mail.decocancun.com';                    
			  $mail->SMTPAuth   = true;                                   
			  $mail->Username   = 'desarrollo3.sistemas@decocancun.com';                    
			  $mail->Password   = 'Wu66iGYlKf';                              
			  $mail->SMTPSecure = 'ssl';         
			  $mail->Port       = 465;                                    
			  //Recipients
			  $mail->setFrom('desarrollo3.sistemas@decocancun.com','Jorge Luis'); 
			  $mail->addAddress('jorge06g92@gmail.com');     
			  //Content
			  $mail->isHTML(true);                                  
			  $mail->Subject = 'Recibiste informacion en la pagina web';
			  $mail->Body    ="
			  <!DOCTYPE html>
			  <html lang='en'>
			  <head>
				  <meta charset='UTF-8'>
				  <meta http-equiv='X-UA-Compatible' content='IE=edge'>
				  <meta name='viewport' content='width=device-width, initial-scale=1.0'>
				  <style class='float-center' type='text/css'>
					  body,
					  html {
						color: black !important;
						background-color: #192a67;
						max-width: 580px!important;
						height: 1000px !important;
						margin: 0 auto;
						padding: 0;
					  }
					  .contenedor {
							background-color: black;
						  	max-width: 580px!important;
						  	height: 1000px !important;
						  	margin: 0 auto;
						  	border-style: solid;
						  	border-color: #CCCC;
					  }
					  .cotenedor-email {
						  
					  }
					  .lista-datos {
						  color: white !important;
						  list-style: none;
						  line-height: 1.5rem;
						  margin-top: 1rem;
						  font-size: 1.2rem !important;
					  }
					  .lista-datos li {
						  margin: 0;
						  padding: 0;
					  }
					  li{
						font-size: 1rem;
					  }
					  h1 {
						  margin-bottom: 2rem;
						  color: white;
						  margin-left: 2.3rem;
					  }
					  h2 {
						  margin-left: 2.3rem;
						  color: white;
					  }
					  .mensaje {
						  color: white;
					  }
					  span {
						  margin-left: 2.3rem;
						  font-size: 1.2rem !important;
					  }
					  p {
						  margin-left: 2.3rem;
						  line-height: 1.5rem;
						  font-size: 1rem;
					  }
					  a{
						color: #ffffff !important;
					  }
					  a:hover {
						  color: #ffffff;
					  }
					  .img-bodas{
						  padding-top: 1rem;
						  width: 150px !important;
						  height: 150px !important;
						  margin-left: 1.3rem;
					  }
					  img{
						  width: 100%!important;
						  height: 100% !important;
					  }
					  .text-color{
						color: white !important;
					}
					.text-color a{
						color: white !important;
					}
					h3,h4{
						color: white !important;
					}
					.table{
						margin-left: 1.3rem;
					}
					.table-title{
						margin-top: 1rem;
					  }
				  </style>
			  </head>
			  
			  <body>
				  <div class='contenedor'>
					  <div class='cotenedor-email'>
						  <div class='img-bodas'>
							  <img src='https://zde.decocancun.com/images/zdlogo.png'>
						  </div>
					  </div>

					<table class='table table-title'>
					  <thead>
						 <tr>
							<th></th>
						 </tr>
					  </thead>
					  <tbody>
						 <tr>
							<td><h3 class='title'>Zuñiga decoraciones</h3></td>
						 </tr>
						 <tr>
						 	<td><h4 class='cliente'>Datos del cliente</h4></td>
					  	</tr>
					  </tbody>
					</table>
					  	<table class='table'>
							<tfoot> 
								<tr class='text-color'>
									<td>Numero de Persona:</td>
									<td colspan='2'>".$datos["numpersona"]."</td>
								</tr>
							</tfoot>
							<tbody>
								<tr class='text-color'>
									<td>Correo:</td>
									<td colspan='2'>".$datos["correo"]."</td>
								</tr>
							</tbody>
						</table>
				  </div>
			  </body>
			  </html>
			  ";	  

			  $mail->Charset='UTF-8';
			  $mail->send();
			 
			  if ($datos>0) {
					$resultado["status"]="success";
					$resultado["mesage"]="Datos enviados";
					echo json_encode($resultado);
			  }
		 
		 } catch (Exception $e) {
			  echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
		 }
	}else{
		 $array = array(
			  'status' 	=>'error',
			  'mesage'	=>'Message not sent',
			  'errors'	=> $errors,
			  'ResExitoso'=>$limpios
		 );
		 echo json_encode($array);
	}



}