<?php

 $pathMainRoot = $_SERVER['DOCUMENT_ROOT'];
 use \PHPMailer\PHPMailer\PHPMailer;
 use \PHPMailer\PHPMailer\SMTP;
 use \PHPMailer\PHPMailer\Exception;
 require  $pathMainRoot ."/saia/api/v1/libs/PHPMailer-master/src/PHPMailer.php";
 require  $pathMainRoot ."/saia/api/v1/libs/PHPMailer-master/src/Exception.php";
 require  $pathMainRoot ."/saia/api/v1/libs/PHPMailer-master/src/SMTP.php";
	
	function sendCustomMail($additionalEmail,$fromEmail,$fromName, $toEmail,$toName,$subject,$contentPlainText,$contentHtml){
		$mail = new PHPMailer(true);
		try {
        	// $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
        	$mail->SMTPDebug = SMTP::DEBUG_OFF; 
        	$mail->isSMTP();                                            //Send using SMTP
        	$mail->Host       = 'mail.saimage-apps.co.za';                     //Set the SMTP server to send through
        	$mail->SMTPAuth   = true;                                   //Enable SMTP authentication
        	$mail->Username   = 'helpdesk@saimage-apps.co.za';                     //SMTP username
        	$mail->Password   = '.@-1slkDk$U.';                               //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($fromEmail, $fromName);
        	$mail->addAddress($toEmail, $toName);     //Add a recipient
        	//$mail->addAddress('connect@pocketstylists.com');
        	if(!$additionalEmail===""){
        	    $mail->addAddress('connect@pocketstylists.com');//Name is optional
        	}
        	
        	$mail->addReplyTo('connect@pocketstylists.com', 'Information');
        	   // $mail->addCC('cc@example.com');
        	   // $mail->addBCC('bcc@example.com');
        
        		//Attachments
        	  //  $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
        	  //  $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name
        
        //====================Content==================
    	    $noData = "";
        	$mail->Subject = $subject;
        	if(strcmp($contentPlainText,$noData)!=0){
        		$mail->isHTML(false); 
        		$mail->Body    = $contentPlainText;
        
        	}
    
        		if(strcmp($contentHtml,$noData)!=0){
        			$mail->isHTML(true); 
        			$mail->AltBody = $contentHtml;
        		}
        
        		$mail->send();
        		return 'Email send';
    	} catch (Exception $e) {
    		return "Email could not be sent. Mailer Error: {$mail->ErrorInfo}";
    	}
		
	}
//$mailSender = new CustomMailSender($pathRoot);
//$mailSender->fromEmail= "developer@pocketstylists.com";
//$mailSender->fromName = "Dev";
//$mailSender->subject = "Test email";
//$mailSender->toEmail = "gits.sa@gmail.com";
//$mailSender->toName = "Emile";
//$mailSender->contentPlainText = "This is a test";
//$mailSender->contentHtml = "";
//$mailSender->apiKey = "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";
//$mailSender->pathToLib = $pathRoot ."/saia/api/v1/libs/sendgrid/sendgrid-php.php";

//$mailSender->sendCustomMail();


?>