<?php

include('PHPMailer/src/Exception.php');
include('PHPMailer/src/PHPMailer.php'); // optional, gets called from within class.phpmailer.php if not already loaded
include('PHPMailer/src/SMTP.php'); 	// optional, gets called from within class.phpmailer.php if not already loaded


use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

//sendMyMsg('edi.hermann@lemonbyte.ro','edi.hermann@lemonbyte.ro','Subject','body<br>line',null,null,null,null);

function sendMyMsg($to,$toname,$subj,$body, $attachment=null , $attachment_name=null ,$attachment_2=null , $attachment_name_2=null )
{
	//Create an instance; passing `true` enables exceptions
	$mail = new PHPMailer(true);

	try {
		//Server settings
		//$mail->SMTPDebug = SMTP::DEBUG_SERVER;                    //Enable verbose debug output
		$mail->isSMTP();                                            //Send using SMTP
		$mail->Host       = 'mail.zadio.bg';                     	//Set the SMTP server to send through
		$mail->SMTPAuth   = true;                                   //Enable SMTP authentication
		$mail->Username   = 'test@zadio.bg';                     	//SMTP username
		$mail->Password   = '6FF%*XK84>NK3mT<';                     //SMTP password
		$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
		$mail->Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

		//Recipients
		$mail->setFrom('cars@zadio.bg', 'cars@zadio.bg');
		$mail->addAddress($to, $toname);     //Add a recipient
		

		//Attachments
		if($attachment!="" && $attachment_name!="")
			$mail->addAttachment($attachment, $attachment_name);         //Add attachments
		if($attachment_2!="" && $attachment_name_2!="")
			$mail->addAttachment($attachment_2, $attachment_name_2);         //Add attachments
		

		//Content
		$mail->isHTML(true);                                  //Set email format to HTML
		$mail->Subject = $subj;
		$mail->Body    = $body;
	  

		$mail->send();
		//echo 'Message has been sent';
	} 
	catch (Exception $e) {
		var_dump($mail->ErrorInfo);exit;
	}
}
