<?php
// start email notification
require_once 'PHPMailerAutoload.php';

// ======================================================
// CONFIGURATION
// ======================================================
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host       = 'mail.tls2u.com';
$mail->Port       = 465;
$mail->SMTPAuth   = true;
$mail->SMTPSecure = 'ssl';
$mail->Username   = 'marketer@tls2u.com';
$mail->Password   = 'tls2up@ssw0rd';
$mail->From       = 'marketer@tls2u.com';
$mail->FromName   = 'TLS2U.COM';

// ======================================================
// EMAIL CONTENT
// ======================================================
// Expected variables before include:
// $email (upline's email)
// $nama (upline's name)
// $username (downline username that triggered bonus)
// $bonus (bonus amount)
// $level (current level of bonus)
// $tarikh (date/time)

$mail->addAddress($uplineEmail, $uplineNama);
$mail->addReplyTo('marketer@tls2u.com', 'TLS2U Support');

$mail->Subject = "Congratulations! Bonus Level $level";

$mail->Body = "
<html>
<head>
  <style>
    body { font-family: Arial, sans-serif; color:#333; }
    .card { background:#f8f9fa; padding:15px; border-radius:8px; border:1px solid #ddd; }
    h2 { color:#007bff; }
  </style>
</head>
<body>
  <h2>Congratulations, {$uplineNama}!</h2>
  <p>You’ve just earned a <strong>Level {$level} Bonus</strong> in your TLS2U.COM network.</p>

  <div class='card'>
    <p><strong>Bonus Level:</strong> {$level}</p>
    <p><strong>Bonus Amount:</strong> RM{$bonus}</p>
    <p><strong>From Downline:</strong> {$username}</p>
    <p><strong>Date:</strong> {$tarikh}</p>
  </div>

  <p>The bonus has been credited into your <strong>CWallet</strong>.</p>
  <p>Log in to your account at <a href='https://vip.tls2u.com'>vip.tls2u.com</a> to check your updated balance and transaction history.</p>

  <p>Keep building your network to unlock more levels and rewards!</p>

  <p>Best Regards,<br>
  <strong>Marketer Team</strong><br>
  The Langkawi Signature (TLS2U.COM)</p>

  <hr>
  <p><small>Please add this sender email (marketer@tls2u.com) to your address book or whitelist to ensure you receive future notifications in your inbox.</small></p>
</body>
</html>
";

$mail->AltBody = "
Congratulations, {$uplineNama}!

You have received a Level {$level} Bonus.

Bonus Level : {$level}
Bonus Amount : RM{$bonus}
From Downline : {$username}
Date : {$tarikh}

The bonus has been credited to your CWallet.

Login to your account at vip.tls2u.com to view your updated balance.

Keep building your network to earn more bonuses!

Regards,
Marketer Team
The Langkawi Signature (TLS2U.COM)
";

if(!$mail->send()) {
    error_log('Mailer Error (Bonus Level): ' . $mail->ErrorInfo);
}
?>
