<?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
// ======================================================

// These variables should already exist before include:
// $email (sponsor email)
// $penajaUsername (sponsor name)
// $usrnm (new member username)
// $pakejName (package name)
// $directSponsor (bonus amount)
$penajaEmail    = $sponsor['email'];
$penajaNama     = $sponsor['nama'];
$mail->addAddress($penajaEmail, $penajaNama);
$mail->addReplyTo('marketer@tls2u.com', 'TLS2U Support');

$mail->Subject = 'Congratulations! Bonus Sponsor';

$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:#28a745; }
  </style>
</head>
<body>
  <h2>Congratulations, {$penajaNama}!</h2>
  <p>You have successfully earned a <strong>Bonus Sponsor</strong> reward.</p>
  
  <div class='card'>
    <p><strong>Bonus Amount:</strong> RM{$directSponsor}</p>
    <p><strong>From Downline:</strong> {$usrnm}</p>
    <p><strong>Package:</strong> {$pakejName}</p>
  </div>

  <p>The bonus has been credited into your <strong>CWallet</strong>.</p>
  <p>You may log in to your account via <a href='https://vip.tls2u.com'>vip.tls2u.com</a> to view your updated balance and transaction history.</p>

  <p>Thank you for being part of TLS2U.COM.</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, {$penajaNama}!

You have received a Bonus Sponsor reward.

Bonus Amount : RM{$directSponsor}
From Downline : {$usrnm}
Package : {$pakejName}

The bonus has been credited to your CWallet.

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

Thank you for being part of TLS2U.COM.

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

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