<?php

    include('../../config/config.php');
    
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    use PHPMailer\PHPMailer\Exception;

    require 'PHPMailer-master/Exception.php';
    require 'PHPMailer-master/PHPMailer.php';
    require 'PHPMailer-master/SMTP.php';
    
    $parent_name =  mysqli_real_escape_string($link,$_POST['parent_firstname']);
    $parent_mname =  mysqli_real_escape_string($link,$_POST['parent_middlename']);
    $parent_lname =  mysqli_real_escape_string($link,$_POST['parent_lastname']);
    
    $funname =  $parent_name.' '.$parent_lname;
    $phone = $_POST['WhatsappNumberfull'];
    $email = $_POST['email'];
    $country = $_POST['country'];
    $state = $_POST['state'];
    $city = $_POST['lga'];
    
    $cityoforigin = mysqli_real_escape_string($link,$_POST['cityorigin']);
    $parentaddress = mysqli_real_escape_string($link,$_POST['parentaddress']);
    
    $session = $_POST['session'];
    $term = $_POST['term'];
    $GroupofSchool = $_POST['GroupofSchool'];
    $phone_no_mainwa = $_POST['WhatsappNumberfullmainwanum'];
    
    
    
      date_default_timezone_set("Africa/Lagos");
    $dateinsert = date("Y-m-d");
    $timeinsert = date("h:i:s");
    

    
    
    $student_firstname = $_POST['childFirstName'];
    $student_midlename = $_POST['childmiddlename'];
    $student_lastname = $_POST['childslastname'];
    $student_class = $_POST['student_class'];
    
    $student_age = $_POST['studentdob'];
    $student_gender = $_POST['studentgender'];
    $institutionID = $_POST['studentinstitution'];
    
    $array_student_name = explode(',', $student_firstname);
    $array_student_midlename = explode(',', $student_midlename);
    $array_sudentlastname = explode(',', $student_lastname);
    $array_class = explode(',',  $student_class);
    $array_age = explode(',', $student_age);
    $institution_array = explode(',',$institutionID);
    $student_gender_array = explode(',', $student_gender);
    // $paymentamount = explode(',',$_POST['amounttotalfinal']);
    
    // $student_classamtfina = explode(',', $_POST['student_classamtfina']);
                
    $student_classcharge = explode(',', $_POST['student_classcharge']);
    
    
    
    
    
    $studenteachamount = explode(',', $_POST['amounttotal']);
    $edumesscharge = explode(',', $_POST['edumesscharge']);
    $vat_by_gov = explode(',', $_POST['vat_by_gov']);
    
    
    
   

    
     function formatPhoneNumber($phoneNumber) {
        // Remove non-numeric characters
        $numericPhoneNumber = preg_replace('/[^0-9]/', '', $phoneNumber);

        // Check if the number starts with '0' and add '234' in that case
        if (substr($numericPhoneNumber, 0, 1) === '0') {
            return '234' . substr($numericPhoneNumber, 1);
        } else {
            // Check if the number starts with '+', if yes, remove the '+'
            if (substr($numericPhoneNumber, 0, 1) === '+') {
                $numericPhoneNumber = substr($numericPhoneNumber, 1);
            }

            // Return the numeric phone number
            return $numericPhoneNumber;
        }
    }


        // Format the phone numbers
        $number = formatPhoneNumber($phone_no_mainwa);

    
    //GET INSTITUTION DETAILS HERE
    
    
               $select_institution = mysqli_query($link,"SELECT * FROM `institution` WHERE InstitutionID='$GroupofSchool'");
               $select_institutioncnt = mysqli_num_rows($select_institution);
               $select_institutioncntrow = mysqli_fetch_assoc($select_institution);
               
               $InstitutionGeneralName = $select_institutioncntrow['InstitutionGeneralName'];
               $InstitutionMotto = $select_institutioncntrow['InstitutionMotto'];
               $InstitutionPhone = $select_institutioncntrow['InstitutionPhone'];
               $InstitutionWebsite = $select_institutioncntrow['InstitutionWebsite'];
               $InstitutionLogo = $select_institutioncntrow['InstitutionLogo'];
                $AgencyOrSchoolOwnerID = $select_institutioncntrow['AgencyOrSchoolOwnerID'];
               
               
                $appstore = $select_institutioncntrow['AppstoreLink'];
               $playstore = $select_institutioncntrow['playstoreLink'];
              
              
               $prosfullschool =  $select_institutioncntrow['InstitutionGeneralName'];
              $schoollink = 'https://'.$select_institutioncntrow['CustomUrl'];
              $file = '';  
              $abba_institution_id = $GroupofSchool;
              
              
                 
              
              
                $select_ischoolowner = mysqli_query($link,"SELECT * FROM `agencyorschoolowner` WHERE AgencyOrSchoolOwnerID='$AgencyOrSchoolOwnerID'");
              
              $select_ischoolownername = mysqli_fetch_assoc($select_ischoolowner);
              $schoolownerid =  $select_ischoolownername['AgencyOrSchoolOwnerID'];
              $schoolownermainno =  $select_ischoolownername['AgencyOrSchoolOwnerMainPhone'];
              $schoolownerwano =  $select_ischoolownername['AgencyOrSchoolOwnerWhatsAppPhone'];
              $schoolownername =  $select_ischoolownername['AgencyOrSchoolOwnerName'];
              
               
               
              
     //GET INSTITUTION DETAILS HERE
    
      $date = date("Y-m-d");
     $studentdetauils = '';
     
     $studentList = "";
    
    foreach($array_student_name as $i => $sudent_arr2)
    {
        $str_firstname = mysqli_real_escape_string($link, $sudent_arr2);  
        $str_lastname = mysqli_real_escape_string($link, $array_sudentlastname[$i]);
        $str_midlename = mysqli_real_escape_string($link, $array_student_midlename[$i]);
        $str_class = $array_class[$i];    
        $str_age = $array_age[$i];  
        $str_institutionid = $institution_array[$i]; 
        $str_studentgender = $student_gender_array[$i];
        
        // $str_student_classamtfina = $student_classamtfina[$i]; 
         $str_student_classcharge = $student_classcharge[$i];
        
        
        $studentchargefinnalamount = $studenteachamount[$i];
        $edumesschargefinal = $edumesscharge[$i];
        $vat_by_govcharge = $vat_by_gov[$i];
        
        
        
        
       $studfullname =  $str_firstname.' '.$str_lastname;
        
        $selectparentcheck = mysqli_query($link,"SELECT * FROM `admissionparentdetails` WHERE InstitutionID='$GroupofSchool' AND ParentFirstName='$parent_name' AND ParentLastName='$parent_lname' AND Phone='$phone'");  
        $selectparentcheckrow = mysqli_fetch_assoc($selectparentcheck);
        $selectparentcheckcnt = mysqli_num_rows($selectparentcheck);
        
        if($selectparentcheckcnt > 0)
        {
            $last_insert_parentid = $selectparentcheckrow['ParentDetailID'];  
        }
        else
        {
            $insert_parent = "INSERT INTO `admissionparentdetails`(`InstitutionID`, `ParentFirstName`, `ParentFMiddleName`, `ParentLastName`, `Phone`, `WhatAppNum`, `Email`, `Country`, `State`, `LGA`, `City`, `HomeAddress`)
            VALUES ('$GroupofSchool','$parent_name','$parent_mname','$parent_lname','$phone','$phone_no_mainwa','$email','$country','$state','$city','$cityoforigin','$parentaddress')";
            $insert_parent_result = mysqli_query($link,$insert_parent);
    
            $last_insert_parentid = mysqli_insert_id($link);  
        }
    
        $insert_child = "INSERT INTO `admissionchilddetails`(`ParentDetailID`, `CampusID`, `FirstName`, `MiddleName`, `LastName`, `AdmissionClassID`, `sessionName`, `Term`, `DOB`, `Gender`, `Date`)
        VALUES ('$last_insert_parentid','$str_institutionid','$str_firstname','$str_midlename','$str_lastname','$str_class','$session','$term','$str_age','$str_studentgender','$date')";
        $insert_child_result = mysqli_query($link,$insert_child);
    
        $last_insert_idstudent = mysqli_insert_id($link);
        
        $selectprefix = mysqli_query($link,"SELECT * FROM `admissionregnumberprifix` WHERE CampusID='$str_institutionid'");  
        $selectprefixrow = mysqli_fetch_assoc($selectprefix);
    
        $preffixxregnum  = $selectprefixrow['RegNumberPrifix'].$last_insert_idstudent; 
                 
         $password = md5(1234);


        $insertuserlogin = mysqli_query($link,"INSERT INTO `userlogin`(`InstitutionIDOrCampusID`,`UserID`,`UserRegNumberOrUsername`,`UserPassword`,`UserType`) 
        VALUES ('$str_institutionid','$last_insert_idstudent','$preffixxregnum','$password','applicant')");
      
        $verifyadmissionpayemnt = mysqli_query($link,"SELECT * FROM `admissionclass` WHERE CampusID='$str_institutionid' AND AdmissionClassID='$str_class' AND PaymentStatus='1' AND PaymentAmount !='0'");
        $verifyadmissionpayemnt_row = mysqli_num_rows($verifyadmissionpayemnt);
        $verifyadmissionpayemnt_fetch  = mysqli_fetch_assoc($verifyadmissionpayemnt);
        
        
               $studentdetauilsnew = '
            <span style="font-size: 14px; line-height: 16px;">
                <strong>'.$str_firstname.' '.$str_midlename.' '.$str_lastname.'</strong>
            </span><br>
            <span style="font-size: 14px; line-height: 16px;">
                '.$InstitutionGeneralName.'<br />Username: '.$preffixxregnum.'
            </span>
            <span style="font-size: 14px; line-height: 16px;">
                <br>Password: 1234
            </span><p></p>
        ';
           
           
           
           $studentListnew = 
                '*Name:* ' . $studfullname . "\n" .
                '*Username:* ' . $preffixxregnum . "\n" .
                '*Password:* ' . '1234' . "\n" .
                '*Url:* ' . $schoollink . "\n";

   
           
           
           
           
           
           $studentdetauils .= $studentdetauilsnew;
        
           $studentList.= $studentListnew;




               if($str_student_classcharge == '0')
               {
                   
                   
                   
                   




                
                   
                   
                   
               }else
               {
                   
                   
                                $do = str_replace('-', '', date("Y-m-d"));
                                $no = str_replace(':', '',date("h:i:s"));
                                $po = rand();
                                $referencenumbero = "RX" . $do . $no . $po . "-" .$last_insert_idstudent;
                                   
                                   
                                     
                                $inserttransaction = mysqli_query($link,"INSERT INTO `wallettransactions`(`UserID`, `UserType`, `TransactionType`, `Amount`, `TransactionFee`, `VatFee`, `Reference`,  `description`, `Date`, `Time`, `Status`) 
                                VALUES ('$last_insert_idstudent','applicant','Admission form','$str_student_classcharge','$edumesschargefinal','$vat_by_govcharge','$referencenumbero','Admission Fee','$dateinsert','$timeinsert','3')");   
                   
                   
                   
               }

        
              
           
    }

          echo 'success';  
           
           
           
           
           
           
           
           $pros_selectappi_details = mysqli_query($link,"SELECT * FROM `whatsappapikey` WHERE InstitutionID='$GroupofSchool'");
          $pros_selectappi_detailscnt = mysqli_num_rows($pros_selectappi_details);
          $pros_selectappi_detailscnt_rows = mysqli_fetch_assoc($pros_selectappi_details);
          
          
          if($pros_selectappi_detailscnt > 0)
          {
              
                $apikey =  $pros_selectappi_detailscnt_rows['ApiKey'];
              
          }else 
          {
              
                        $pros_selectappi_details_default = mysqli_query($link,"SELECT * FROM `whatsappapikey` WHERE InstitutionID='0' AND Purpose='Default'");
                      $pros_selectappi_detailscnt_default = mysqli_num_rows($pros_selectappi_details_default);
                      $pros_selectappi_detailscnt_rows_default = mysqli_fetch_assoc($pros_selectappi_details_default);
                      
                       $apikey =   $pros_selectappi_detailscnt_rows_default['ApiKey'];
                 
          }
                                               
                                                   include('../messaging/whatsapp/send_whatapp_msg.php');

                  
                   
                                                     $msg = rawurlencode(
                                                        'Dear ' . $funname . ',' . "\n\n" .
                                                        'Welcome to ' . $prosfullschool . '! Your registration is successful.' . "\n\n" .
                                                        'Below are your kids login details:' . "\n\n" .
                                                        $studentList . "\n" .
                                                        'Please keep your login information confidential. If you have any questions or concerns, feel free to contact us.' . "\n\n" .
                                                        'Thank you' . "\n\n" .
                                                        '*(powered by EduMESS)*'
                                                    );
                                                
                                                    send_whatsapp_msg($abba_institution_id, $number,$apikey, $msg, $file);       
       
            
            

           $htmlcontent.='<!DOCTYPE html

                PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html  xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"
                xmlns:o="urn:schemas-microsoft-com:office:office">
            
            <head>
            
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
                <meta name="viewport" content="width=device-width, initial-scale=1.0">
                <meta name="x-apple-disable-message-reformatting">
                <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes">
                <meta name="format-detection" content="telephone=no, date=no, address=no, email=no, url=no">
                <meta name="x-apple-disable-message-reformatting">
                <!--[if !mso]><!-->
                <meta http-equiv="X-UA-Compatible" content="IE=edge">
                <!--<![endif]-->
                <title></title>
            
                <style type="text/css">
                    @media only screen and (min-width: 620px) {
                        .u-row {
                            width: 600px !important;
                        }
            
                        .u-row .u-col {
                            vertical-align: top;
                        }
            
                        .u-row .u-col-33p33 {
                            width: 199.98px !important;
                        }
            
                        .u-row .u-col-66p67 {
                            width: 400.02px !important;
                        }
            
                        .u-row .u-col-100 {
                            width: 600px !important;
                        }
                    }
            
                    @media (max-width: 620px) {
                        .u-row-container {
                            max-width: 100% !important;
                            padding-left: 0px !important;
                            padding-right: 0px !important;
                        }
            
                        .u-row .u-col {
                            min-width: 320px !important;
                            max-width: 100% !important;
                            display: block !important;
                        }
            
                        .u-row {
                            width: 100% !important;
                        }
            
                        .u-col {
                            width: 100% !important;
                        }
            
                        .u-col>div {
                            margin: 0 auto;
                        }
                    }
            
                    body {
                        margin: 0;
                        padding: 0;
                    }
            
                    table,
                    tr,
                    td {
                        vertical-align: top;
                        border-collapse: collapse;
                    }
            
                    p {
                        margin: 0;
                    }
            
                    .ie-container table,
                    .mso-container table {
                        table-layout: fixed;
                    }
            
                    * {
                        line-height: inherit;
                    }
                             a[x-apple-data-detectors="true] {
                             color: inherit !important;
                             text-decoration: none !important;
                              }
                  
            
                    table,
                    td {
                        color: #000000;
                    }
            
                    #u_body a {
                        color: #0000ee;
                        text-decoration: underline;
                    }
                </style>
            
            
            
            
                <link href="https://fonts.googleapis.com/css?family=Cabin:400,700" rel="stylesheet" type="text/css">
            
            
            </head>
            
            <body xml:lang="en" class="clean-body u_body"
                style="margin: 0;padding: 0;-webkit-text-size-adjust: 100%;background-color: #faf9f9;color: #000000">
            
                <table id="u_body"
                    style="border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;min-width: 320px;Margin: 0 auto;background-color: #faf9f9;width:100%"
                    cellpadding="0" cellspacing="0">
                    <tbody>
                        <tr style="vertical-align: top">
                            <td style="word-break: break-word;border-collapse: collapse !important;vertical-align: top">
            
            
            
                                <div class="u-row-container" style="padding: 0px;background-color: transparent">
                                    <div class="u-row"
                                        style="Margin: 0 auto;min-width: 320px;max-width: 600px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">
                                        <div
                                            style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
            
                                            <div class="u-col u-col-100"
                                                style="max-width: 320px;min-width: 600px;display: table-cell;vertical-align: top;">
                                                <div style="height: 100%;width: 100% !important;">
            
                                                    <div
                                                        style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;">
            
            
                                                        <table style="font-family:\'Cabin\',sans-serif;" role="presentation"
                                                            cellpadding="0" cellspacing="0" width="100%" border="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:\'Cabin\',sans-serif;"
                                                                        align="left">
            
                                                                        <table width="100%" cellpadding="0" cellspacing="0"
                                                                            border="0">
                                                                            <tr>
                                                                                <td style="padding-right: 0px;padding-left: 0px;"
                                                                                    align="left">
            
                                                                                    <img align="left" border="0"
                                                                                        src="https://assets.unlayer.com/projects/145304/1678799684381-edumes-blue.png"
                                                                                        alt="" title=""
                                                                                        style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 18%;max-width: 104.4px;"
                                                                                        width="104.4" />
            
                                                                                </td>
                                                                            </tr>
                                                                        </table>
            
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
            
            
                                                    </div>
            
                                                </div>
                                            </div>
            
                                        </div>
                                    </div>
                                </div>
            
            
            
                                <div class="u-row-container" style="padding: 0px;background-color: transparent">
                                    <div class="u-row"
                                        style="Margin: 0 auto;min-width: 320px;max-width: 600px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: #ffffff;">
                                        <div
                                            style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
            
                                            <div class="u-col u-col-100"
                                                style="max-width: 320px;min-width: 600px;display: table-cell;vertical-align: top;">
                                                <div style="height: 100%;width: 100% !important;">
            
                                                    <div
                                                        style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;">
            
            
                                                        <table style="font-family:\'Cabin\',sans-serif;" role="presentation"
                                                            cellpadding="0" cellspacing="0" width="100%" border="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:\'Cabin\',sans-serif;"
                                                                        align="left">
            
                                                                        <table width="100%" cellpadding="0" cellspacing="0"
                                                                            border="0">
                                                                            <tr>
                                                                                <td style="padding-right: 0px;padding-left: 0px;"
                                                                                    align="center">
            
                                                                                    <img align="center" border="0"
                                                                                        src="https://assets.unlayer.com/projects/145304/1678799725879-email_image%20for%20abba.png"
                                                                                        alt="" title=""
                                                                                        style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 100%;max-width: 580px;"
                                                                                        width="580" />
            
                                                                                </td>
                                                                            </tr>
                                                                        </table>
            
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
            
            
                                                    </div>
            
                                                </div>
                                            </div>
            
                                        </div>
                                    </div>
                                </div>
            
            
            
                                <div class="u-row-container" style="padding: 0px;background-color: transparent">
                                    <div class="u-row"
                                        style="Margin: 0 auto;min-width: 320px;max-width: 600px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: #ffffff;">
                                        <div
                                            style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
            
                                            <div class="u-col u-col-100"
                                                style="max-width: 320px;min-width: 600px;display: table-cell;vertical-align: top;">
                                                <div style="height: 100%;width: 100% !important;">
            
                                                    <div
                                                        style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;">
            
            
                                                        <table style="font-family:\'Cabin\',sans-serif;" role="presentation"
                                                            cellpadding="0" cellspacing="0" width="100%" border="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="overflow-wrap:break-word;word-break:break-word;padding:0px 55px 10px 30px;font-family:\'Cabin\',sans-serif;"
                                                                        align="left">
            
                                                                        <div
                                                                            style="font-size: 10px; line-height: 160%; text-align: left; word-wrap: break-word;">
                                                                            <p style="font-size: 14px; line-height: 160%;"><span
                                                                                    style="font-size: 14px; line-height: 16px;">Hi
                                                                                    '.$parent_lname.',</span></p>


                                                                            <p style="font-size: 14px; line-height: 160%;"></p>
                                                                            <p style="font-size: 14px; line-height: 160%;"><span
                                                                                    style="font-size: 16px; line-height: 16px;"><strong><span
                                                                                            style="line-height: 16px;">Admission
                                                                                            Application 
                                                                                            to '.$InstitutionGeneralName.' is Successful.</span></strong>
                                                                                </span>
                                                                            </p>
                                                                            <p style="font-size: 14px; line-height: 160%;"></p>
                                                                            
                                                                            <p style="font-size: 14px; line-height: 160%;">
                                                                           
                                                                                    <span style="font-size: 14px; line-height: 16px; color: #292929;"><span
                                                                                        style="line-height: 16px;"><strong>Congratulations!</strong></span>
                                                                                    Your appication  has been submitted succesfully,
                                                                                    An account has been created for the applicant in
                                                                                    order to check his/her admission status. Below
                                                                                    are your login information:</span>
                                                                            </p>
                                                                            
                                                                            <p style="font-size: 14px; line-height: 160%;"></p>
                                                                            
                                                                    
                                                                            
                                                                            
                                                                            
                                                                                    '.$studentdetauilsfinal.'  
                                                                                    
                                                                               
                                                                     </div>
            
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
                                                          <p style="font-size: 14px; line-height: 160%;"></p>
                                                        <table style="font-family:\'Cabin\',sans-serif;" role="presentation"
                                                            cellpadding="0" cellspacing="0" width="100%" border="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:\'Cabin\',sans-serif;"
                                                                        align="left">
            
            
                                                                        <div align="center">
                                                                        
                                                                                    
                                                                                                                                                                  
                                                                                  
            
                                                                            <a href="'.$defaultUrl.'login/multilogin.php?oid='.$schoolownerid.'" target="_blank" class="v-button"
                                                                                style="box-sizing: border-box;display: inline-block;font-family:\'Cabin\',sans-serif;text-decoration: none;-webkit-text-size-adjust: none;text-align: center;color: #FFFFFF; background-color: #296beb; border-radius: 4px;-webkit-border-radius: 4px; -moz-border-radius: 4px; width:100%; max-width:100%; overflow-wrap: break-word; word-break: break-word; word-wrap:break-word; mso-border-alt: none;font-size: 16px;">
                                                                                <span
                                                                                    style="display:block;padding:14px 44px 13px;line-height:120%;">
                                                                                        <span style="line-height: 19.2px;"><strong><span
                                                                                                style="line-height: 19.2px;">Click here to Login
                                                                                                </span></strong>
                                                                                                </span>
                                                                                   
                                                                                </span>
                                                                            </a>
            
                                                                        </div>
            
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
            
                                                        <table style="font-family:\'Cabin\',sans-serif;" role="presentation"
                                                            cellpadding="0" cellspacing="0" width="100%" border="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:\'Cabin\',sans-serif;"
                                                                        align="left">
            
                                                                        <div
                                                                            style="font-size: 13px; line-height: 140%; text-align: center; word-wrap: break-word;">
                                                                            <p style="line-height: 140%;">If you have any questions,
                                                                                please don\'t hesitate to contact us <span
                                                                                    style="color: #3598db; line-height: 18.2px;">'.$schoolownermainno.'</span>,
                                                                                 or Chat us on <a href="https://wa.me/'.$schoolownerwano.'"
                                                                                    style="color: #2dc26b; line-height: 18.2px;">WhatsApp
                                                                                    '.$schoolownerwano.'.</a></p>
                                                                        </div>
             
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
            
                                                        <table style="font-family:\'Cabin\',sans-serif;" role="presentation"
                                                            cellpadding="0" cellspacing="0" width="100%" border="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:\'Cabin\',sans-serif;"
                                                                        align="left">
            
                                                                        <table height="0px" align="center" border="0"
                                                                            cellpadding="0" cellspacing="0" width="100%"
                                                                            style="border-collapse: collapse;table-layout: fixed;border-spacing: 0;mso-table-lspace: 0pt;mso-table-rspace: 0pt;vertical-align: top;border-top: 1px solid #BBBBBB;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%">
                                                                            <tbody>
                                                                                <tr style="vertical-align: top">
                                                                                    <td
                                                                                        style="word-break: break-word;border-collapse: collapse !important;vertical-align: top;font-size: 0px;line-height: 0px;mso-line-height-rule: exactly;-ms-text-size-adjust: 100%;-webkit-text-size-adjust: 100%">
                                                                                        <span>&#160;</span>
                                                                                    </td>
                                                                                </tr>
                                                                            </tbody>
                                                                        </table>
            
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
            
                                                        <table style="font-family:\'Cabin\',sans-serif;" role="presentation"
                                                            cellpadding="0" cellspacing="0" width="100%" border="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="overflow-wrap:break-word;word-break:break-word;padding:0px 55px 9px 23px;font-family:\'Cabin\',sans-serif;"
                                                                        align="left">
            
                                                                        <div
                                                                            style="line-height: 160%; text-align: left; word-wrap: break-word;">
                                                                            <p style="line-height: 160%; font-size: 14px;">Warm
                                                                                regards,<br />'.$schoolownername.'<br />School Owner.</p>
                                                                        </div>
            
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
            
            
                                                    </div>
            
                                                </div>
                                            </div>
            
                                        </div>
                                    </div>
                                </div>
            
            
            
                                <div class="u-row-container" style="padding: 0px;background-color: transparent">
                                    <div class="u-row"
                                        style="Margin: 0 auto;min-width: 320px;max-width: 600px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">
                                        <div
                                            style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
            
                                            <div class="u-col u-col-100"
                                                style="max-width: 320px;min-width: 600px;display: table-cell;vertical-align: top;">
                                                <div
                                                    style="height: 100%;width: 100% !important;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
            
                                                    <div
                                                        style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
            
            
                                                        <table style="font-family:\'Cabin\',sans-serif;" role="presentation"
                                                            cellpadding="0" cellspacing="0" width="100%" border="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:\'Cabin\',sans-serif;"
                                                                        align="left">
            
                                                                        <div
                                                                            style="font-size: 13px; line-height: 130%; text-align: left; word-wrap: break-word;">
                                                                            <p style="line-height: 130%;">Download School Mobile
                                                                                App.</p>
                                                                        </div>
            
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
            
            
                                                    </div>
            
                                                </div>
                                            </div>
            
                                        </div>
                                    </div>
                                </div>
            
            
            
                                <div class="u-row-container" style="padding: 0px;background-color: transparent">
                                    <div class="u-row"
                                        style="Margin: 0 auto;min-width: 320px;max-width: 600px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">
                                        <div
                                            style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
            
                                            <div class="u-col u-col-33p33"
                                                style="max-width: 320px;min-width: 200px;display: table-cell;vertical-align: top;">
                                                <div
                                                    style="height: 100%;width: 100% !important;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
            
                                                    <div
                                                        style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
            
            
                                                        <table style="font-family:\'Cabin\',sans-serif;" role="presentation"
                                                            cellpadding="0" cellspacing="0" width="100%" border="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:\'Cabin\',sans-serif;"
                                                                        align="left">
            
                                                                        <table width="100%" cellpadding="0" cellspacing="0"
                                                                            border="0">
                                                                            <tr>
                                                                                <td style="padding-right: 0px;padding-left: 0px;"
                                                                                    align="left">
            
                                                                                    <a href="'.$playstore.'"><img align="left" border="0"
                                                                                        src="https://assets.unlayer.com/projects/145304/1678802826342-appstre.png"
                                                                                        alt="" title=""
                                                                                        style="outline: none;text-decoration: none;-ms-interpolation-mode: bicubic;clear: both;display: inline-block !important;border: none;height: auto;float: none;width: 74%;max-width: 133.2px;"
                                                                                        width="133.2" /><a>
            
                                                                                </td>
                                                                            </tr>
                                                                        </table>
            
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
            
            
                                                    </div>
            
                                                </div>
                                            </div>
                                            <div class="u-col u-col-66p67"
                                                style="max-width: 320px;min-width: 400px;display: table-cell;vertical-align: top;">
                                                <div
                                                    style="height: 100%;width: 100% !important;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
            
                                                    <div
                                                        style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
            
            
            
                                                    </div>
            
                                                </div>
                                            </div>
            
                                        </div>
                                    </div>
                                </div>
            
            
            
                                <div class="u-row-container" style="padding: 0px;background-color: transparent">
                                    <div class="u-row"
                                        style="Margin: 0 auto;min-width: 320px;max-width: 600px;overflow-wrap: break-word;word-wrap: break-word;word-break: break-word;background-color: transparent;">
                                        <div
                                            style="border-collapse: collapse;display: table;width: 100%;height: 100%;background-color: transparent;">
            
                                            <div class="u-col u-col-100"
                                                style="max-width: 320px;min-width: 600px;display: table-cell;vertical-align: top;">
                                                <div
                                                    style="height: 100%;width: 100% !important;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
            
                                                    <div
                                                        style="box-sizing: border-box; height: 100%; padding: 0px;border-top: 0px solid transparent;border-left: 0px solid transparent;border-right: 0px solid transparent;border-bottom: 0px solid transparent;border-radius: 0px;-webkit-border-radius: 0px; -moz-border-radius: 0px;">
            
            
                                                        <table style="font-family:\'Cabin\',sans-serif;" role="presentation"
                                                            cellpadding="0" cellspacing="0" width="100%" border="0">
                                                            <tbody>
                                                                <tr>
                                                                    <td style="overflow-wrap:break-word;word-break:break-word;padding:10px;font-family:\'Cabin\',sans-serif;"
                                                                        align="left">
            
                                                                        <div
                                                                            style="font-size: 14px; line-height: 140%; text-align: center; word-wrap: break-word;">
                                                                            <p style="line-height: 140%;">Powered
                                                                                By<br /><strong><a href="https://www.edumess.com">EduMESS Inc.</a></strong></p>
                                                                        </div>
            
                                                                    </td>
                                                                </tr>
                                                            </tbody>
                                                        </table>
            
            
                                                    </div>
            
                                                </div>
                                            </div>
            
                                        </div>
                                    </div>
                                </div>
            
            
            
                            </td>
                        </tr>
                    </tbody>
                </table>
            
            </body>
            
            </html>';
            
            
           

                
                
                
                  $selectserveretails = mysqli_query($link,"SELECT * FROM `serverpassword`");
                  $selectserveretailscnt = mysqli_fetch_assoc($selectserveretails);
                  
                 $servername =  $selectserveretailscnt['ServerName'];
                 $serverpwd =  $selectserveretailscnt['ServerPassword'];
                   
                 $email_to =  'hello@edumess.com';
                 $delivery = 'hello@edumess.com';
                 $altmess = 'alt';
                
                
                
           
            // = 'emaildelivery@schoolportalgenerator.com';
            $nameto = '';
            $subject = 'Admission Application';
            
            $mail = new PHPMailer(true);

    try {
        //Server settings
        $mail->SMTPDebug = 0;                      //Enable verbose debug output
        $mail->isSMTP();                                            //Send using SMTP
        $mail->Host       = 'chovgroup.com';                     //Set the SMTP server to send through
        $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
        $mail->Username   = $servername;                     //SMTP username
        $mail->Password   = $serverpwd;                             //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($delivery,$InstitutionGeneralName);
        $mail->addAddress($email, $nameto);     //Add a recipient
        $mail->addAddress($email);               //Name is optional
        $mail->addReplyTo($email_to, $nameto);
        $mail->addCC($email);
        $mail->addBCC($email);

    
        //Content
        $mail->isHTML(true);                                  //Set email format to HTML
        $mail->Subject = $subject;
        $mail->Body = $htmlcontent;
        $mail->AltBody = $htmlcontent;

        $mail->send();
        
    } catch (Exception $e) {

   
    }
    
    ?>