<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require $_SERVER['DOCUMENT_ROOT'] . '/auth/mailer/src/PHPMailer.php';
require $_SERVER['DOCUMENT_ROOT'] . '/auth/mailer/src/SMTP.php';
require $_SERVER['DOCUMENT_ROOT'] . '/auth/mailer/src/Exception.php';

function sendWelcomeEmail($toEmail, $firstName) {
    $mail = new PHPMailer(true);

    try {
        // SMTP settings
        $mail->isSMTP();
$mail->Host       = 'gobolchain.info';   // from cPanel
$mail->SMTPAuth   = true;
$mail->Username   = 'admin@gobolchain.info';
$mail->Password   = 'YOUR_EMAIL_PASSWORD'; // reset in cPanel if unsure
$mail->SMTPSecure = 'ssl';  // because port 465
$mail->Port       = 465;

        // Sender
        $mail->setFrom('admin@gobolchain.info', 'Gobolcoin Network');
        $mail->addAddress($toEmail, $firstName);

        // Email content
        $mail->isHTML(true);
        $mail->Subject = "Welcome to Gobolcoin Network 🚀";

  $mail->Body = '
        <!DOCTYPE html>
        <html>
        <head>
          <meta charset="UTF-8">
          <style>
            body { font-family: Arial, sans-serif; background-color: #f8f8f8; margin:0; padding:0; }
            .container { max-width:600px; margin:20px auto; background:#ffffff; border-radius:8px; overflow:hidden; box-shadow:0 2px 6px rgba(0,0,0,0.1); }
            .header { background-color:#8B0000; padding:20px; text-align:center; color:#fff; }
            .header img { height:40px; vertical-align:middle; margin-right:8px; }
            .header h1 { display:inline-block; font-size:20px; margin:0; vertical-align:middle; }
            .content { padding:20px; color:#333; }
            h2 { color:#8B0000; }
            .button { display:inline-block; background:#8B0000; color:#fff; padding:12px 20px; margin:15px 0; border-radius:6px; text-decoration:none; }
            .footer { background:#f1f1f1; padding:15px; text-align:center; font-size:12px; color:#555; }
            .links a { margin:0 8px; text-decoration:none; color:#8B0000; }
          </style>
        </head>
        <body>
          <div class="container">
            <div class="header">
              <img src="https://gobolchain.info/logo.png" alt="Gobolcoin Logo">
              <h1>Gobolcoin Network</h1>
            </div>
            <div class="content">
              <h2>Welcome to Gobolcoin Network!</h2>
              <p>Dear ' . htmlspecialchars($firstName) . ',</p>
              <p>Welcome to <b>Gobolcoin</b>, the community-driven project where mining meets innovation! We are thrilled to have you onboard.</p>

              <h3>Logging In</h3>
              <p>You can access your mining dashboard by clicking the button below:</p>
              <p><a href="https://gobolchain.info/login.php" class="button">Login to Your Dashboard</a></p>
              <p>Use your email address and the password you set during signup to log in.</p>

              <h3>Email Verification</h3>
              <p>For security and to access all features, please verify your email address by logging in to your dashboard and following the verification steps.</p>

              <h3>Getting Support</h3>
              <p>If you have any questions or need help, we are always here for you:</p>
              <p>
                <a href="https://gobolchain.info/support.html" class="button">Submit a Ticket</a>
                <a href="https://gobolchain.info/faq.html" class="button">FAQ</a>
              </p>

              <p><b>Next Steps:</b> Complete your KYC in the dashboard to unlock full mining rewards and referral bonuses.</p>

              <p>We look forward to helping you grow with <b>Gobolcoin</b>!</p>
              <p>— The Gobolcoin Team 🚀</p>
            </div>
            <div class="footer">
              <div class="links">
                <a href="https://gobolchain.info">Visit Website</a> | 
                <a href="https://gobolchain.info/login.php">Login</a> | 
                <a href="https://gobolchain.info/support.html">Get Support</a>
              </div>
              <p>Copyright © 2025 Gobolcoin Network. All rights reserved.</p>
            </div>
          </div>
        </body>
        </html>';

        if (!$mail->send()) {
    error_log("Mailer Error: " . $mail->ErrorInfo); // logs to error_log, no output
    return false;
} else {
    return true;
}

    } catch (Exception $e) {
        error_log("Mailer Error: " . $mail->ErrorInfo);
        return false;
    }
}