<?php 
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

//Create an instance; passing `true` enables exceptions


function sendLoginOTP($email, $accnmbr, $name){
global $conn;

$code =  substr(time()*rand(), 0, 4); 

$selPinExists = $conn->query("select * from login_pin where accnt = '$accnmbr'") or die($conn->error); 
if($selPinExists->num_rows){
$updateCode = $conn->query("update login_pin set pin = '$code' where accnt = '$accnmbr'") or die($conn->error);
}else{
$insPin = $conn->query("insert into login_pin (pin, accnt, stat, date_cr) values ('$code', '$accnmbr', 'Active', '" . date("Y-m-d H:i:s") . "')") or die($conn->error);	
}


$message = '<html><body style="padding: 20px;">';

$message .= '<div style="width: 100%; display:inline; float: left; ">';

$message .= '<p style="color:rgba(0, 0, 0, 0.5); font-size:15px; font-family:Helvetica; padding;9px; margin:10px 0px 10px 10px;">Hi '. $name .'</p>';

$message .= '<div style="padding:10px;">';
$message .= '<p style="color:rgba(0, 0, 0, 0.5); font-size:15px; font-family: calibri">
The following details have logged into your Online Bank </b>
 </p>
<h3 style="color:rgba(0, 0, 0, 0.8); font-family: calibri; font-size: 19px; text-align=center; width:100%; padding-left: 50px">
Name: <b>'.  $name  . '</b><br>
Accnt Number: <b>'.  $accnmbr  . '</b>
 </h3>
  <p style="color:rgba(0, 10, 60, 0.5);font-size:15px; font-family: calibri; padding: 20px 0px; font-weight:100 ">
For enquiries and complaints, contact support at support@rtrustonline.com.  
</p>
<p style="font-size: 15px; font-family: Helvetica">
Connex Credit Union will NEVER send you a link to any external website or request your personal banking details via e-mail, telephone or in person. 
 </p>
 <p style="color:#0E35BE;font-size:18px;">
 You are advised to  
always keep your log-on details safe and never disclose it to anyone. 
  </p>';

$message .= '<p style="color:rgba(0, 0, 9, 0.8); line-height: 22px; font-size:12px; font-family: Helvetica;"> Connex Credit Union  is a private Banking Division and is a leading provider of advisory and capital markets services to corporate and financial sponsor clients across the globe. With banking professionals across the Americas, Europe and Asia, we leverage our industry-specific expertise and regional market insight to serve the evolving needs of our clients. The deep sector knowledge of our industry coverage teams allows us to provide our clients with unique market insight on a full range of financing alternatives and strategic opportunities. Leveraging our leading institutional distribution platform, our goal is to provide our clients with solutions across all banking products, including initial public offerings, follow-on offerings, wall-crossed offerings, bought deals, private placements, ATMs, convertible offerings, leveraged loans, investment grade and high-yield debt offerings and all forms of advisory services.</p>';

$message .= '</div></div';

$message .= '</body></html>';




$mail = new PHPMailer(true);

try {
    //Server settings
    //$mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
    $mail->isSMTP();                                            //Send using SMTP
    $mail->Host  = 'mail.frnbk.com';                     //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username  = 'support@frnbk.com';                     //SMTP username
    $mail->Password   = '=~5Ubu&(Mw+l';                               //SMTP password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
    $mail->Port       = 2080;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

    //Recipients
    $mail->setFrom('info@rtrustonline.com', 'Connex Credit Union');
    $mail->addAddress($email, $name);     //Add a recipient
    $mail->addReplyTo('info@rtrustonline.com', 'Connex Credit Union');
    // $mail->addCC('cc@example.com');
    // $mail->addBCC('bcc@example.com');

    //Attachments
    // $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
    // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = "Login Notification";
    $mail->Body    = $message;
    

    $mail->send();
    return 1;
} catch (Exception $e) {
    return 0; 
    //echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}


}


function sendRegister($email,  $name){

$message = '<html><body style="padding: 20px;">';

$message .= '<div style="width: 100%; display:inline; float: left; ">';

$message .= '<p style="color:rgba(0, 0, 0, 0.5); font-size:15px; font-family:Helvetica; padding;9px; margin:10px 0px 10px 10px;">Hello '. $name .'</p>';

$message .= '<div style="padding:10px;">';
$message .= '<p style="color:rgba(0, 0, 0, 0.5); font-size:15px; font-family: calibri">
Your Account Registeration has been succesfully completed. </b>
 </p>

 <p style="color:rgba(0, 10, 60, 0.5);font-size:15px; font-family: calibri; padding: 20px 0px; font-weight:100 ">
Customer care representative will get back to you .  
<b>
Connex Credit Union will NEVER send you a link to any external website or request your personal banking details via e-mail, telephone or in person. 
 </p><p style="color:#0E35BE;font-size:18px;">
 You are advised to  
always keep your log-on details safe and never disclose it to anyone. 
  </p>';

$message .= '<p style="color:rgba(0, 0, 9, 0.8); line-height: 22px; font-size:12px; font-family: Helvetica;"> Connex Credit Union  is a private Banking Division and is a leading provider of advisory and capital markets services to corporate and financial sponsor clients across the globe. With banking professionals across the Americas, Europe and Asia, we leverage our industry-specific expertise and regional market insight to serve the evolving needs of our clients. The deep sector knowledge of our industry coverage teams allows us to provide our clients with unique market insight on a full range of financing alternatives and strategic opportunities. Leveraging our leading institutional distribution platform, our goal is to provide our clients with solutions across all banking products, including initial public offerings, follow-on offerings, wall-crossed offerings, bought deals, private placements, ATMs, convertible offerings, leveraged loans, investment grade and high-yield debt offerings and all forms of advisory services.</p>';

$message .= '</div></div';

$message .= '</body></html>';




$mail = new PHPMailer(true);

try {
    //Server settings
    //$mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
    $mail->isSMTP();                                            //Send using SMTP
    $mail->Host  = 'metroonlinegroup.co.uk';                     //Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username  = 'info@metroonlinegroup.co.uk';                     //SMTP username
    $mail->Password   = 'WSuu3BqUS49;';                               //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('info@metroonlinegroup.co.uk', 'Connex Credit Union');
    $mail->addAddress($email, $name);     //Add a recipient
    $mail->addReplyTo('info@metroonlinegroup.co.uk', 'Connex Credit Union');
    // $mail->addCC('cc@example.com');
    // $mail->addBCC('bcc@example.com');

    //Attachments
    // $mail->addAttachment('/var/tmp/file.tar.gz');         //Add attachments
    // $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    //Optional name

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = "Metro-Bank Login OTP";
    $mail->Body    = $message;
    

    $mail->send();
    return 1;
} catch (Exception $e) {
    return 0; 
    //echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}


}


?>