<?php

namespace App\Http\Controllers;

use PHPMailer\PHPMailer\PHPMailer;

class Send_mail{
	
	private $host_smtp;
	private $Port;
	private $Username;
	private $Password;
	
	function __construct($host, $Port, $Username, $Password )
    {
        $this->host_smtp = $host;
		$this->Port = $Port;
		$this->Username = $Username;
		$this->Password = $Password;
    }
	
	public function enviar_correo($mensaje, $correo_destino, $name_destinatario, $asunto){
		
		$mail = new PHPMailer;
		$mail->isSMTP();
		$mail->SMTPDebug = 0;// 2=bug  0=produccion
		$mail->Host = $this->host_smtp;
		$mail->Port = $this->Port;
		$mail->SMTPAuth = true;
		$mail->Username = $this->Username;
		$mail->Password = $this->Password;
		$mail->setFrom($this->Username , 'Sistema TPV');
		$mail->addReplyTo($this->Username , 'Sistema TPV');
		$mail->addAddress($correo_destino, $name_destinatario);
		$mail->Subject = $asunto;
		$mail->msgHTML("<HTML><div>". $mensaje ."</div></HTML>");
		$mail->AltBody = 'This is a plain text message body';
		$mail->addAttachment('test.txt');
		
		if (!$mail->send()) {
			return 0;
		} else {
			return 1;
		}
		
	}
	
	
}