<?php
session_start();


require_once ("../../config/Datos.php");

require '../../libreriasphp/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();


$mail->setLanguage('es','../../libreriasphp/phpmailer/language');
$mail->CharSet = "UTF-8";
//$mail->IsSMTP();
$mail->SMTPDebug = 0;//Enable SMTP debugging // 0 = off (for production use) // 1 = client messages // 2 = client and server messages 
$mail->Debugoutput = 'html';//Ask for HTML-friendly debug output  
$mail->Host = $d_sc_Host;//Set the hostname of the mail server  
$mail->Port = $d_sc_Port;//Set the SMTP port number - likely to be 25, 465 or 587  
$mail->SMTPAuth = $d_sc_SMTPAuth;//Whether to use SMTP authentication 
//$mail->SMTPSecure = $d_sc_SMTPSecure;
$mail->Username = $d_sc_Username; //Username to use for SMTP authentication 
$mail->Password = $d_sc_Password; //Password to use for SMTP authentication

$usu_ema_nom="FACTURACION GRUPO VYF";
$usu_ema='ecomprobantes@grupovyf.com';

$mail->setFrom($usu_ema,$usu_ema_nom); //correo envío
$mail->addReplyTo($usu_ema,$usu_ema_nom); //Responder a correo

$mail->addAddress(trim($_POST['txt_cli_ema']),trim($_POST['txt_cli_con'])); //Destinatario

//$mail->addCC(trim($_POST['txt_cli_emacop']),trim($_POST['txt_cli_concop'])); //con copia

$asunto=trim($_POST['txt_cor_asu']);
$asunto=utf8_encode("=?UTF-8?B?".base64_encode($asunto)."?=");
$mail->Subject = $asunto; 

$mail->AltBody = 'Su gestor de correo electrónico no soporta mensajes en HTML. Por lo tanto no podrá ver el contenido.'; //Replace the plain text body with one created manually 


$pdf = 'pdf/'.$_POST['emp_numdoc'].'_'.$_POST['hdd_numdoc'].'_'.$_POST['cli_numdoc'].'.pdf';
$xml = '../../docfirmado/'.$_POST['emp_numdoc'].'-09-'.$_POST['hdd_numdoc'].'.zip';

$mail->addAttachment($pdf);
$mail->addAttachment($xml);



$body.=$_POST['txt_cor_men'];

$mail->Body = $body; // Mensaje a enviar

	if (!$mail->send())
	{
		$res="Error: " . $mail->ErrorInfo; 
		$est = 0;
	}else {
	/* $xac=1;
	$tip=1;//1 email
	$oVentacorreo->insertar(
		$xac,
		$_SESSION['usuario_id'],
		$_POST['hdd_cli_id'],
		$_POST['hdd_ven_id'],
		$tip,
		$usu_ema,
		trim($_POST['txt_cli_ema']),
		trim($_POST['txt_cli_emacop']),
		trim($_POST['txt_cor_asu']),
		$body,
		$archivos
	);
  	 */
  	 $est = 1;
		$res="Correo Electronico enviado."; 
	} 

$data['ven_corr_est']=$est;
$data['ven_corr_msj']=$res;
echo json_encode($data);

?>