<?php namespace App\Controllers;
use App\Models\FieldModel;
use App\Models\InvoiceModel;
use App\Models\UserModel;
use App\Models\NewsModel;
use App\Models\ScheduleModel;
use App\Models\FacultyModel;
use App\Models\CourseModel;
use App\Models\CountryModel;
use App\Models\CenterModel;
use App\Models\ApplicationModel;
use App\Models\CourseOutlineModel;
use App\Controllers\Proforma;

class SendMail extends BaseController
{
    private $cats;
    private $course;


    function __construct(){
        $facultyModel=new FacultyModel();
        $this->$cats=$facultyModel->orderBy('facultyName', 'ASC')->findAll();

    }

    public function index() 
	{
		$data['cats']=$this->$cats;
        $courseModel= new CourseModel();
        $data['trendings'] = $courseModel->join('durationtypes','courses.durationType=durationtypes.typeID')->orderBy('courseID', 'ASC')->limit(4)->findAll();

        $courseModel= new CourseModel();
        $data['recents'] = $courseModel->join('durationtypes','courses.durationType=durationtypes.typeID')->orderBy('courseID', 'DESC')->limit(4)->findAll();

        $scheduleModel = new ScheduleModel();
    $data['schedules']=$scheduleModel->getUpcomingSchedules();
        echo view('templates/header',$data);
        return view('form_view');
        echo view('templates/footer', $data);
    }

    function sendMail() { 
        $name = $this->request->getVar('name');
        $to = $this->request->getVar('mailTo');
        $subject = $this->request->getVar('subject');
        $message = $this->request->getVar('message');
        
        $email = \Config\Services::email();

        $email->setTo($to, $name);
        $email->setFrom('info@soaringskillsinstitute.com', 'Confirm Registration');
        $email->setCC('info@soaringskillsinstitute.com');
         $email->setBCC('training@soaringskillsinstitute.com');
          //$email->setBCC('info@soaringskillsinstitute.com');
        
        $email->setSubject($subject);
        $email->setMessage($message);

        if ($email->send()) 
		{
		   // header ('Location: ../../contact-us');
		  echo "Email successfully sent";
echo "<script>setTimeout(\"location.href = 'https://soaringskillsinstitute.com/contact-us';\",1500);</script>";
        //    echo 'Email successfully sent';
            
        } 
		else 
		{
            $data = $email->printDebugger(['headers']);
            print_r($data);
        }
    }

}