<?php

class class_mail {

	var $config;

	var $mail;

	function __construct($config){ 
	    
	    $this->config = $config;
	    require_once($this->config->getValue("includes_path","").'/phpmailer/class.phpmailer.php');
	    $this->mail = new PHPMailer(true);
	    $this->mail->IsSMTP();
	    $this->mail->SMTPDebug  = $this->config->getValue("email","Debug");
	    $this->mail->SMTPAuth   = $this->config->getValue("email","Auth");
	    $this->mail->SMTPSecure = $this->config->getValue("email","Secure");
	    $this->mail->Host       = $this->config->getValue("email","Host");
	    $this->mail->Port       = $this->config->getValue("email","Port");
	    $this->mail->Username   = $this->config->getValue("email","Username");
	    $this->mail->Password   = $this->config->getValue("email","Password");
	}

	function sendMail($szekcio,$modultype,$body) {

	    try {
	      $this->mail->SetFrom($this->config->getValue("email","Username"), $this->config->getValue($szekcio,"from_error_name"));
	      $this->mail->AddAddress($this->config->getValue($szekcio,"to_error_email"), $this->config->getValue($szekcio,"to_error_name"));
	      $this->mail->Subject = $modultype.": ".$this->config->getValue($szekcio,"error_message");
	      $this->mail->MsgHTML($body);
	      $this->mail->Send();

	    } catch (phpmailerException $e1) {
	      file_put_contents($this->config->getValue("log_path","")."/pgmail_".date("Y-m-d").".log", date("Y.m.d H:i:s")." ".$e1->getMessage()."\n", FILE_APPEND);
	    } catch (Exception $e2) {
	      file_put_contents($this->config->getValue("log_path","")."/pgmail_".date("Y-m-d").".log", date("Y.m.d H:i:s")." ".$e2->getMessage()."\n", FILE_APPEND);
	    };

	}

}
?>
