<?php
// for use PHP Mailer without composer : 

// ex. Create a folder in root/PHPMAILER
// Put on this folder this 3 files find in "src" 
// folder of the distribution : 
// PHPMailer.php , SMTP.php , Exception.php

// include PHP Mailer
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// include dirname(__DIR__) . '/hrm/PHPMAILER/PHPMailer.php';
// include dirname(__DIR__) . '/hrm/PHPMAILER/SMTP.php';
// include dirname(__DIR__) . '/hrm/PHPMAILER/Exception.php';
require_once($_SERVER['DOCUMENT_ROOT']."/hrm/PHPMAILER/PHPMailer.php");
require_once($_SERVER['DOCUMENT_ROOT']."/hrm/PHPMAILER/SMTP.php");
require_once($_SERVER['DOCUMENT_ROOT']."/hrm/PHPMAILER/Exception.php");

// i made a function 

/*
    *
    * Function send_mail_by_PHPMailer($to, $from, $subject, $message);
    * send a mail by PHPMailer method
    * @Param $to -> mail to send
    * @Param $from -> sender of mail
    * @Param $subject -> suject of mail
    * @Param $message -> html content with datas
    * @Return true if success / Json encoded error message if error 
    * !! need -> classes/Exception.php - classes/PHPMailer.php - classes/SMTP.php
    *
    */
function send_mail_by_PHPMailer($to, $subject, $message, $path=null)
{

    // SEND MAIL by PHP MAILER
    $from = 'consultants@mncconsulting.co.ke'; //maill to send from
    $mail = new PHPMailer();
    $mail->CharSet = 'UTF-8';
    $mail->isSMTP(); // Use SMTP protocol
    $mail->Host = 'mail.mncconsulting.co.ke';
    $mail->SMTPAuth = true; // Auth. SMTP
    $mail->SMTPAutoTLS = false;
    $mail->Username = 'consultants@mncconsulting.co.ke';
    $mail->Password = "Consultants@2022"; // your pass mail box
    $mail->SMTPSecure = 'false'; // Accept SSL
    $mail->Port = '587'; // port of your out server
    $mail->setFrom($from); // Mail to send at
    $mail->addAddress($to); // Add sender
    $mail->addReplyTo($from); // Adress to reply
    $mail->isHTML(true); // use HTML message
    $mail->Subject = $subject;
    $mail->Body = $message;
    if ($path!=null){
        echo 'am attached'.$path;
    $mail->addAttachment($path); 
    }

    // SEND
    if (!$mail->send()) {

        // render error if it is
        $tab = array('error' => 'Mailer Error: ' . $mail->ErrorInfo);
        echo json_encode($tab);
        exit;
    } else {
        // return true if message is send
        return true;
    }
}
    /*
    *
    * END send_mail_by_PHPMailer($to, $from, $subject, $message)
    * send a mail by PHPMailer method
    *
    */
  
    // use function :
    //  $to = "cmurilla@gmail.com";
    //  //$from ="test@wintec.co.ke";
    // $subject = "Mail test";
    //  $message = "test 1";
   // send_mail_by_PHPMailer($to, $subject, $message);
