<?php namespace App\Controllers;
class Sender{
// 	$email = \Config\Services::email();

public function sendEmail($mail){

// Recipient
$to = $mail["emailAddress"];

// Sender
$from = 'paulgichohi@gmail.com';
$fromName = 'Soaring Skills Training Institute';

$setCC = 'info@soaringskillsinstitute.com';
// Email subject
$subject = 'Invitation for a Training Course';

// Attachment file
$file = $mail['file'];

if(!empty($file) > 0){
    
    $path = 'public/images/apps/';
    
    $filename = $path.$file;
     
    if(file_exists($filename))
    {
       $realfile = $filename;//.$filename;
    }
}

// Email body content
$htmlContent = '
    

  <div>
  <img src="http://soaringskillsinstitute.com/public/images/logo.png" alt="Soaring Skills Training Institute Header"/>
  </div>
  <div style="font-family:verdana;margin-left:10px;font-size:10pt;color:#5F6368">
  Dear '.$mail["name"].',<br>
  We invite you for  training course on '.$mail["courseName"].' to be held from '.$mail["startDate"].' to '.$mail["endDate"].'.<br/>
  Please find attached the Official Invitation letter to present during admission.
  <div class="col-md-6">Name</div>
  <div class="col-md-6">'.$mail["name"].'</div><br/>
  <div class="col-md-6">Invoice No. '.$mail['invoiceId'].'</div>
  <div class="col-md-6">'.$mail["invoiceId"].'</div>
 
  Regards,<br/>
  Nixon Kahuria<br/>
  Head of Training <br/>
  Skills For Africa.<br/>
  </div>

<div>
<img src="http://soaringskillsinstitute.com/public/images/footer.png" alt="Soaring Skills Training Institute"/>
</div>

';
// email stuff (change data below)
$to = "paulgichohi@gmail.com"; 
$from = "paulgichohi@gmail.com"; 
$subject = "send email with pdf attachment"; 
$message = "<p>Please see the attachment.</p>";

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

// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;

// attachment name
//$filename = "invoice.pdf";


// if(!empty($file) > 0){
    
//     $path = 'public/images/apps/';
    
//     $filename = $path.$file;
     
//     if(file_exists($filename))
//     {
//       $realfile = $filename;//.$filename;
//     }
// }

// encode data (puts attachment in proper format)
// $mail->addStringAttachment($pdf->Output('S'), 'OrderDetails.pdf');
 
$attachment = chunk_split(base64_encode($pdfdoc));

// main header
$headers  = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

// no more headers after this, we start the body! //

$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$body .= "This is a MIME encoded message.".$eol;

// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$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.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";

// send message
mail($to, $subject, $body, $headers, $message);
}
}