<?php

/*
  Created on : Mayo 26, 2019, 01:14:34 PM
  Author     : Gabriel Hernandez Gonzalez
 */
 
	require_once "core_classes.php";					
	require_once "PHPMailer.php";
	require_once "SMTP.php";	
	require_once "Exception.php";
	require_once "OAuth.php";
	
	require_once '/dompdf/autoload.inc.php';


	switch (filter_input(INPUT_POST, 'tipoOperacion')) {

		case 'enviarNotificacion':
		
			$pBodyMail = filter_input(INPUT_POST, 'pBody');
			$pListaCorreos = filter_input(INPUT_POST, 'pListaCorreos');
										 
			$mail = new PHPMailer\PHPMailer\PHPMailer();
			 
			$response = new root_response;
			try {
				
				$mail->SMTPDebug = 0;                                       // Enable verbose debug output
				$mail->isSMTP();                                            // Set mailer to use SMTP
				$mail->Host       = 'smtp.gmail.com';  // Specify main and backup SMTP servers
				$mail->Port       = 465;                                    // TCP port to connect to
				$mail->SMTPSecure = 'ssl';                                  // Enable TLS encryption, `ssl` also accepted
				$mail->SMTPAuth   = true;                                   // Enable SMTP authentication
				$mail->Username   = 'premiumteamdeveloper@gmail.com';      // SMTP username
				$mail->Password   = 'mfcg.team';                            // SMTP password
				

				//Recipients
				$mail->setFrom('premiumteamdeveloper@gmail.com', '25/09/2019');
				
				/*$vArrayCorreos = explode(',', $pListaCorreos);
				foreach($vArrayCorreos as $correo){					
					$mail->addAddress($correo);// Name is optional
				}*/
				
				$mail->addAddress('isc.ghernandez@gmail.com');// Name is optional

				// Content
				$mail->isHTML(true);                                  // Set email format to HTML
				$mail->Subject = "DEMO";
				$mail->Body    = $pBodyMail;
				$mail->send();
				
				$response->transaccion = "1";
				$response->mensaje = "Correo enviado correctamente...!!!";
							
			} catch (Exception $e) {
				$response->transaccion = "0";
				$response->mensaje = "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";				
			}	
			
			echo json_encode($response);
								
			break;
			
		default:
			echo json_encode(system_get_message(SISTEMA_PARAMETRO_NO_RECONOCIDO));
			break;
	}

        
?>
