<?php

function sendOTP_email($email, $userID){
global $conn;

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

$updateCode = $conn->query("update customer_info set tok_code = '$code' where customer_id = '$userID'") or die($conn->error);

//Fetch Customer details 
$fetchCustdetails = $conn->query("select * from customer_info where customer_id = '$userID'") or die($conn->error);
$custDetial = $fetchCustdetails->fetch_assoc();


$to = $email;
$subject = 'OTP Code';
$from = 'info-desk@sgate.com';
$replyto ='no-reply@sgate.com';

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$trans_id = substr(time()*rand(), 0, 14);
// Create email headers
$headers .= 'From: '. $to ."\r\n".
    'Reply-To: '. $to ."\r\n" .
    'X-Mailer: PHP/' . phpversion();
 
// Compose a simple HTML email message
$message = '<html><body style="padding:10px;">';
$message .= '<div style="width:100%; display:block; padding:0px 0px; border-bottom: 5px solid #00AAD9; margin-bottom:30px;"><img src="img/logo-2x.png" width="160" height="80" style="margin:18px 5px;"/></div>';

$message .= '<p style="color:#2D0497; font-size:14px; font-family:Verdana; padding;9px; margin:10px 0px 10px 0px;"><b>Hello ' .  $custDetial["cust_name"]. '</b></p>';
$message .= '<div style="padding:10px;">';
$message .= '<p style="color:rgba(0, 0, 0, 0.8); font-size:1em; font-family: calibri">
Below is your Login OTP code. </b>
 </p>
<h3 style="color:rgba(0, 0, 0, 0.6); font-family: calibri; font-size: 1.4em; text-align=center; width:400px;">
'.  $code  . '
 </h3>
 <p style="color:rgba(0, 10, 60, 0.5);font-size:18px; font-family: calibri; padding: 20px 0px; font-weight:100 ">
For enquiries and complaints, contact support at support@cvibsplc.com.  
<b>
Pacific Western Bank (PWB)  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, 0, 0.4); font-size:1em; font-family: calibri; font-weight: 100; margin-top:30px;"> Pacific Western Bank (PWB)  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>';
$message .= '</body></html>';
 

 



// Sending email
if(@mail($to, $subject, $message, $headers)){
   return 1;
} else{
return 0;
}
}

?>