<?
/*
Autor: L.I. Carlos Alberto Vaca Coronado
Version 2.0.1
*/
?>
<?
use PHPMailer\PHPMailer\PHPMailer;
 
Function SendMail($ParaEmail,$ParaNombre,$SubjectMessage,$BodyHTMLFileMessage,$AdjuntoA,$AdjuntoB,$AdjuntoC,$correoCC,$nombreCC)
{


//require_once('class.phpmailer.php');
// include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
// require('PHPMailerAutoload.php');
require_once('PHPMailer.php');
require_once('SMTP.php');
require_once('Exception.php');

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch

	 $mail->IsSMTP();
	 $mail->SMTPOptions = array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
    )
);

try {
	$mail->IsSMTP(); // telling the class to use SMTP
  $mail->Host       = "smtp.googlemail.com"; // SMTP server
  $mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
  $mail->SMTPAuth   = true;                  // enable SMTP authentication
  // $mail->SMTPSecure = "tls";                 // sets the prefix to the servier
  $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
  $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
  $mail->Username   = "lsanchez@disxii.com";  // GMAIL username
  $mail->Password   = "osel0193";            // GMAIL password
  // $mail->SetLanguage('es', 'lenguaje/');            // GMAIL password
  $mail->AddReplyTo('lsanchez@disxii.com', 'Portal de Recepcion CFD');
  
  $emails = explode(";",$ParaEmail);
  
  $names = explode(";",$ParaNombre);
  for($i=0;$i < count($emails);$i++){
	$mail->AddAddress($emails[$i], $names[$i]);
  }
  
  if(trim($correoCC) != "" && trim($nombreCC) != ""){
	  $eCC = explode(";",$correoCC);
	  $nCC = explode(";",$nombreCC);
	  for($i=0;$i < count($eCC);$i++){
		$mail->AddBCC($eCC[$i], $nCC[$i]);
	  }
  }
  
  $mail->SetFrom('ebecerra.demo@gmail.com', 'Portal de Recepcion CFD');
  
  $mail->Subject = $SubjectMessage;
  
  $mail->AltBody = 'Correo electrónico, enviado desde el sistema de DISPRO!'; // optional - MsgHTML will create an alternate automatically
  /*if (file_exists($BodyHTMLFileMessage)) {
    $mail->MsgHTML(file_get_contents($BodyHTMLFileMessage));
  } else {
    $mail->MsgHTML("No se especifico el cuerpo del mensaje o no existe el archivo indicado");  
  }*/
  
  $mail->MsgHTML($BodyHTMLFileMessage);
  
  
    if (file_exists($AdjuntoA)) {
        $mail->AddAttachment($AdjuntoA); }
    if (file_exists($AdjuntoB)) {
        $mail->AddAttachment($AdjuntoB); }
    if (file_exists($AdjuntoC)) {
        $mail->AddAttachment($AdjuntoC); }
  
  //$mail->Send();
  if(!$mail->Send()) {
      //echo "<p>: </p>\n" . $mail->ErrorInfo;
			/*echo "<script language='javascript'>
				alert('No se pudo enviar un correo a su cuenta.');
			</script>";*/
			return false;
    } else {
			/*echo "<script language='javascript'>
			alert('En breves instantes recibira un correo.');
			</script>";*/
			return true;
    }
  
  //echo "Message Sent OK</p>\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
  return false;
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
  return false;
}



}

?> 
