<?php
// $postData = $uploadedFile = $statusMsg = '';
// $msgClass = 'errordiv';
if(isset($_POST['selectedcheckbox']) && $_POST['selectedcheckbox']!=""){

          
   $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>";
$attachment=$_POST['attachment'];

   

$filename = preg_replace('/^.+[\\\\\\/]/', '', $attachment);
//echo $filename;
$filename =str_replace(" ","_","$filename");
//$filename = 'chemistry.pdf';
    $path = '/liveclass/uplaods';
    //$file = $path . "/" . $filename;
    $file = dirname(__DIR__).$path ."/" . $filename;
    $mailto = $emails ;
    $subject = $subject;
    $message = $message;

    $content = file_get_contents($file);
    $content = chunk_split(base64_encode($content));

    // a random hash will be necessary to send mixed content
    $separator = md5(time());

    // carriage return type (RFC)
    $eol = "\r\n";

    // main header (multipart mandatory)
    $headers = "From: BPATCSC <bpatcsc@bpatcsc.org>" . $eol;
    $headers .= "MIME-Version: 1.0" . $eol;
    $headers .= "Content-Type: multipart/mixed; boundary=\"" . $separator . "\"" . $eol;
    $headers .= "Content-Transfer-Encoding: 7bit" . $eol;
    $headers .= "This is a MIME encoded message." . $eol;

    // message
    $body = "--" . $separator . $eol;
    $body .= "Content-Type: text/plain; charset=\"UTF-8\"" . $eol;
    $body .= "Content-Transfer-Encoding: 8bit" . $eol;
    $body .= $message . $eol;

    // attachment
    $body .= "--" . $separator . $eol;
    $body .= "Content-Type: application/octet-stream; name=\"" . $filename . "\"" . $eol;
    $body .= "Content-Transfer-Encoding: base64" . $eol;
    $body .= "Content-Disposition: attachment" . $eol;
    $body .= $content . $eol;
    $body .= "--" . $separator . "--";

    //SEND Mail
    if (mail($mailto, $subject, $body, $headers)) {
        echo "mail send ... OK"; // or use booleans here
    } else {
        echo "mail send ... ERROR!";
        print_r( error_get_last() );
    }



    // $messagee = '';

        
    //     require 'class/class.phpmailer.php';
    //     $mail = new PHPMailer;
    //     //$mail->IsSMTP();								//Sets Mailer to send message using SMTP
    //     $mail->Host = 'smtp.gmail.com';		//Sets the SMTP hosts of your Email hosting, this for Godaddy
    //     $mail->Port = '587';								//Sets the default SMTP server port
    //     $mail->SMTPAuth = true;							//Sets SMTP authentication. Utilizes the Username and Password variables
    //     $mail->Username = 'hasanbpatcsc@gmail.com';					//Sets SMTP username
    //     $mail->Password = 'hasan460608';					//Sets SMTP password
    //     $mail->SMTPSecure = 'tls';							//Sets connection prefix. Options are "", "ssl" or "tls"
    //     $mail->From = 'hasanbpatcsc@gmail.com';			//Sets the From email address for the message
    //     $mail->FromName = 'BPATCSC';			//Sets the From name of the message
    //     //$mail->AddAddress("$emails", "");		//Adds a "To" address
    //     $mail->WordWrap = 50;							//Sets word wrapping on the body of the message to a given number of characters
    //     $mail->IsHTML(true);							//Sets message type to HTML				
    //     $mail->AddAttachment($file);     				//Adds an attachment from a path on the filesystem
    //     $mail->Subject = "$subject";			//Sets the Subject of the message
    //     $mail->Body = "$message";				//An HTML or plain text message body
       
       
       
       
    //     foreach($emails as $email){
        
    //         //$mail->setFrom($email, 'Webs Codex');
    //         $mail->addAddress($email, '');              // Add a recipient
    //         //$mail->addReplyTo($email, 'Webs Codex');
    
    //         //$mail->Subject = $subject;
    //         //$mail->Body    = $message;
    
    //         // if($mail->send()){
    //         //     $esMessage = true;
    //         // }else{
    //         //     $esMessage = false;
    //         // }
        
    //         if($mail->Send())								//Send an Email. Return true on success or false on error
    //         {
    //             //$messagee = '<label class="text-success">Customer Details has been send successfully...</label>';
    //         echo "mail sent";
            
    //         }
        
        
        //}
       
       
       
       
       
       
    









}
?>