<?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__) . '/crm/PHPMAILER/PHPMailer.php';
include dirname(__DIR__) . '/crm/PHPMAILER/SMTP.php';
include dirname(__DIR__) . '/crm/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 = 'bensnjo@gmail.com'; //maill to send from
    //$from = 'qa1/revenue@revenue.go.ke';
    $mail = new PHPMailer();
    $mail->CharSet = 'UTF-8';
    $mail->isSMTP(); // Use SMTP protocol
    //$mail->Host = '192.168.4.1'; // Specify  SMTP server
    //$mail->Host = '10.160.8.17';
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = false; // Auth. SMTP
    $mail->SMTPAutoTLS = false;
    $mail->Username = 'bensnjo@gmail.';
    //$mail->Username = 'qa1/revenue@revenue.go.ke'; // Mail who send by PHPMailer
    $mail->Password = "kelvingitaukamau"; // your pass mail box
    //$mail->Password = "password1"; // your pass mail box
    $mail->SMTPSecure = 'false'; // Accept SSL
    $mail->Port = '25'; // 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){
    $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 = "wycliffmuriithi@gmail.com";
     //$from ="test@wintec.co.ke";
    $subject = "Mail test";
     $message = "test 1";
    //send_mail_by_PHPMailer($to, $subject, $message);
