<?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       = 'mail.setiveracruz.com.mx';  // Specify main and backup SMTP servers
				$mail->Port       = 26;                                    // TCP port to connect to
				$mail->SMTPSecure = 'tls';                                  // Enable TLS encryption, `ssl` also accepted
				$mail->SMTPAuth   = true;                                   // Enable SMTP authentication
				$mail->Username   = 'notificacionessios@setiveracruz.com.mx';                     // SMTP username
				$mail->Password   = 'vg223*r^!pvA.';                               // SMTP password
				

				//Recipients
				$mail->setFrom('notificacionessios@setiveracruz.com.mx', 'Reporte de Servicios de Amarradores');
			
				
				/*$vArrayCorreos = explode(',', $pListaCorreos);
				foreach($vArrayCorreos as $correo){					
					$mail->addAddress($correo);// Name is optional
				}*/
				
				$mail->addAddress('whernandez@setiveracruz.com.mx');// 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;
	}

        
?>
