<?php 
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

function send_email($email,$name, $subject, $body)
{ 
    //Load Composer's autoloader
    require 'vendor/autoload.php';
    
    //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       = 'silrak.lv';                //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username   = 'infos@silrak.lv';                     //SMTP username
    $mail->Password   = ']q%atC0U#R9d';                               //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('infos@silrak.l', 'Silrak');
    $mail->addAddress($email, $name);     //Add a recipient
 

    //Attachments
  //  $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
    // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = $subject;
    $mail->Body    = '<table style="width:100%;border:1px solid lightgray"><tr><td style="text-align:left;border-bottom:1px solid lightgray;;padding:15px"><img src="https://www.1pavars.lv/admin/images/logo.png" style="max-width:150px" /></td></tr><tr><td><b style="font-size:17px;;padding:15px">' . $body . '</b></td></tr><tr><td style="border-top:1px solid lightgray;padding:15px">Regards,<br/>1pavars<br/>www.1pavars.lv</td></tr></table>';
    $mail->AltBody = 'This is an html mail. Please kindle change to html mails';
    if(!$mail->send())
    {
        return 0;
    } 
    else
    {
        return 1;
    }
    
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
    return 0;
}
    
    
    
    

    /* SMTP */

	/*require_once 'PHPMailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;

    $mail->isSMTP();                                      // Set mailer to use SMTP
  //  $mail->SMTPDebug = 4;      
    $mail->Host = '1pavars.lv';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'infos@1pavars.lv';                 // SMTP username
    $mail->Password = ']q%atC0U#R9d';
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = '465';


    $mail->setFrom('infos@1pavars.lv', '1pavars');
    $mail->addAddress($email, $name);
    $mail->Subject = $subject;
    $mail->Body    = '<table style="width:100%;border:1px solid lightgray"><tr><td style="text-align:left;border-bottom:1px solid lightgray;;padding:15px"><img src="https://www.1pavars.lv/admin/images/logo.png" style="max-width:150px" /></td></tr><tr><td><b style="font-size:17px;;padding:15px">' . $body . '</b></td></tr><tr><td style="border-top:1px solid lightgray;padding:15px">Regards,<br/>1pavars<br/>www.1pavars.lv</td></tr></table>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    if(!$mail->send())
    {
        return 0;
    } 
    else
    {
        return 1;
    }*/

/*ini_set('sendmail_from', 'noreplay@clusterinfos.com');
ini_set('sendmail_path', '/usr/sbin/sendmail -t -i -f noreplay@clusterinfos.com');
$headers = "From: noreplay@clusterinfos.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
						//$headers .= "Reply-To: shayasmk@gmail.com\r\n";
						$headers .= "MIME-Version: 1.0\r\n";
						$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
						$headers .= "X-Mailer: PHP/".phpversion();   

						return mail('shayasmk@gmail.com',$subject, $body, $headers); */

}
