<?php 
// Database connection
$servername = "localhost";
$db_username = "karamelh_bmg";
$db_password = "karamelh_bmg";
$database = "karamelh_bmg";

$myConn= $conn= $con = new mysqli($servername, $db_username, $db_password, $database);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
                
$adminemail="support@bmgssd.com.ng";              
$sitename = "Forex Trade";
$siteurl = "https://karamelhub.com.ng/bmg"; //do not add ending /

//SMTP SETUP

$siteemail = "mail@karamelhub.com.ng";

$email_pass = "@@mailpass##";

$email_host = "karamelhub.com.ng";


//WALLET ADDRESS SETUP

$btc_wallet = "BTCXXXXXXXXXXXXXXXXXXXXXXXX";

$eth_wallet = "ETHXXXXXXXXXXXXXXXXXXXXXXXX";

$usdt_wallet = "USDTXXXXXXXXXXXXXXXXXXXXXXXX";

$ltc_wallet = "LTCXXXXXXXXXXXXXXXXXXXXXXXX";

$tron_wallet = "TRONXXXXXXXXXXXXXXXXXXXXXXXX";


require 'PHPMailer/src/PHPMailer.php';
require 'PHPMailer/src/SMTP.php';
require 'PHPMailer/src/Exception.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;


function sendmail($email, $username, $subject, $message)
{
    global $siteemail, $email_pass, $email_host, $siteurl, $sitename;
    
    $mail = new PHPMailer(true);

    try {
        // Server settings
        $mail->isSMTP();
        $mail->Host = $email_host;
        $mail->SMTPAuth = true;
        $mail->Username = $siteemail;
        $mail->Password = $email_pass;
        $mail->SMTPSecure = 'ssl'; // Use 'tls' for port 587, 'ssl' for port 465
        $mail->Port = 465;

        // Recipients
        $mail->setFrom($siteemail, $sitename);
        $mail->addAddress($email, $username);

        // Content
        $mail->isHTML(true);
        $mail->Subject = $subject;
        $mail->Body = $message;
        $mail->AltBody = strip_tags($message); // Fallback plain text

        $send = $mail->send();
        return $send;
    } catch (Exception $e) {
        return "Mailer Error: {$mail->ErrorInfo}";
    }
}
