<?php
  use PHPMailer\PHPMailer\PHPMailer;
  use PHPMailer\PHPMailer\Exception;
  require_once 'PHPMailer/vendor/autoload.php';
if(isset($_POST['selectedcheckbox']) && $_POST['selectedcheckbox']!=""){

    //require_once ('PHPMailer/PHPMailerAutoload.php');
    
  
        
        $emails  = $_POST['selectedcheckbox'];
         $subject =$_POST['mailsubject']; //"Send Bulk Email in PHP using PHPMailer with Ajax JQuery";
        $message =$_POST['smstext']; //"<br>Powered By Webs Codex <br><br>Web: <a href='https://www.webscodex.com/' target='_blank'>Webs Codex</a>";

        //$mail = new PHPMailer(true);
        
        $mail = new PHPMailer(TRUE);
	$mail->SMTPDebug = 3;                                 // Enable verbose debug output
	$mail->CharSet="UTF-8";                               // Put right encoding here  
	$mail->isSMTP();                                      // Set mailer to use SMTP
	$mail->Host = 'smtp.gmail.com';  					  // Specify main and backup SMTP servers
	$mail->SMTPAuth = true;                               // Enable SMTP authentication
	$mail->Username = 'hasanbpatcsc@gmail.com';                  // SMTP username
	$mail->Password = 'hasan460608';                // SMTP password
	$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
	$mail->Port = 587;                                    // TCP port to connect to
	$mail->isHTML(true); 								  // Set email format to HTML
	
	$mail->SMTPOptions = array(
        'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
        )
    );




    foreach($emails as $email){
        
        $mail->setFrom($email, 'bpatcsc');
        $mail->addAddress($email, '');              // Add a recipient
        $mail->addReplyTo($email, 'bpatcsc');

    	$mail->Subject = $subject;
    	$mail->Body    = $message;


        
        if($mail->send()){
            $esMessage = true;
        }else{
    	    $esMessage = false;
        }


    }
    
    if($esMessage){
        echo'<div class="alert alert-success alert-dismissible">
                <button type="button" class="close" data-dismiss="alert">&times;</button>
                Email sent successfully
            </div>';
        exit;
    }else{
        echo'<div class="alert alert-danger alert-dismissible"> 
                <button type="button" class="close" data-dismiss="alert">&times;</button>
                Email not sent to Please try again or type correct email!
            </div>';
        exit;           
    }



}







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

// require 'D:\xampp\htdocs\sms\PHPMailer\vendor\autoload.php';

// $mail = new PHPMailer(TRUE);

// try {
   
//    $mail->setFrom('darth@empire.com', 'Darth Vader');
//    $mail->addAddress('palpatine@empire.com', 'Emperor');
//    $mail->Subject = 'Force';
//    $mail->Body = 'There is a great disturbance in the Force.';
   
//    /* SMTP parameters. */
//    $mail->isSMTP();
//    $mail->Host = 'smtp.empire.com';
//    $mail->SMTPAuth = TRUE;
//    $mail->SMTPSecure = 'tls';
//    $mail->Username = 'smtp@empire.com';
//    $mail->Password = 'iamyourfather';
//    $mail->Port = 587;
   
//    /* Disable some SSL checks. */
//    $mail->SMTPOptions = array(
//       'ssl' => array(
//       'verify_peer' => false,
//       'verify_peer_name' => false,
//       'allow_self_signed' => true
//       )
//    );
   
//    /* Finally send the mail. */
//    $mail->send();
// }
// catch (Exception $e)
// {
//    echo $e->errorMessage();
// }
// catch (\Exception $e)
// {
//    echo $e->getMessage();
// }

?>