<?php
// Include PHPMailer classes (no Composer)
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

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

// Get form data
$userName = $_POST['name'];
$userEmail = $_POST['email'];

$mail = new PHPMailer(true);

try {
    // SMTP server configuration
    $mail->isSMTP();
    $mail->Host       = 'mail.capitaluniondigital.online';     // SMTP server
    $mail->SMTPAuth   = true;
    $mail->Username   = 'support@capitaluniondigital.online';      // Your Gmail address
    $mail->Password   = 'capitaluniondigital83$59';         // Gmail App Password
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
    $mail->Port       = 465;

    // Email content
    $mail->setFrom('support@capitaluniondigital.online', 'capitaluniondigital.online');
    $mail->addAddress($b_email, $b_firstname);
    $mail->isHTML(true);
    $mail->Subject = 'Welcome to Our Platform!';
    $mail->Body    = "
        <h2>Hello $b_firstname,</h2>
        <p>Thank you for registering on our site!</p>
        <p>We’re happy that you are on board.</p>
        <p>ACCOUNT ID - $account_id</p>
        <p>PASSWORD - $b_password</p>
        <p>PIN - $account_pin</p><br><br>
        <p>– Management</p>
    ";

    $mail->send();
    echo "<script>alert('Signup successful! A welcome email has been sent to $b_email.');</script>";
} catch (Exception $e) {
    echo "<script>alert('Signup successful, but email could not be sent. Error: {$mail->ErrorInfo} ');</script>";
}
?>
