<?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    header("Content-Type: application/json");

    include('config.php');

    date_default_timezone_set("Asia/Kolkata");

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    require '../vendor/autoload.php';

    $requestData = json_decode(file_get_contents("php://input"), true);

    $teamId = $requestData['team_id'] ?? '';
    $ccList = $requestData['cc']      ?? [];
    $email  = $requestData['email']   ?? '';

    $filePath   = "https://www.procorporateleague.com/2026/pcl/assets/mail_image/";
    $imgVersion = time();

    /* ── PCL OVERALL STATS ── */
    $statscurl = curl_init();
    curl_setopt_array($statscurl, [
        CURLOPT_URL            => 'https://procorporateleague.com/pcl_rest/api/v1/pcl/stats',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING       => '',
        CURLOPT_MAXREDIRS      => 10,
        CURLOPT_TIMEOUT        => 10,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST  => 'GET'
    ]);
    $statsResponse = curl_exec($statscurl);
    curl_close($statscurl);
    $statsJson = json_decode($statsResponse, true);
    $statsArrayData = [
        'total_matches_played'  => $statsJson['results'][0]['Total_Matches_Played']  ?? 0,
        'total_runs_Scored'     => $statsJson['results'][0]['Total_Runs_Scored']     ?? 0,
        'total_wickets_Claimed' => $statsJson['results'][0]['Total_Wickets_Claimed'] ?? 0,
        'total_hundreds'        => $statsJson['results'][0]['Total_Hundreds']        ?? 0,
        'total_fifties'         => $statsJson['results'][0]['Total_Fifties']         ?? 0,
    ];

    /* ── TEAM AI PROFILE ── */
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL            => "https://procorporateleague.com/pcl_rest/api/v12/teams/{$teamId}/ai-profile",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING       => '',
        CURLOPT_MAXREDIRS      => 10,
        CURLOPT_TIMEOUT        => 8,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST  => 'GET',
    ));
    $response = curl_exec($curl);
    curl_close($curl);

    $teamData = json_decode($response, true);

    $profile = [];
    if (!empty($teamData) && !empty($teamData['data'])) {
        $profile = $teamData['data'][0] ?? [];
    }

    $LogoUrl = 'https://procorporateleague.com/wp-includes/images/team/' . rawurlencode((string)($profile['team_id'] ?? '')) . '.png';

    /* ── OLD TEAM MAP DATA ── */
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL            => 'https://www.procorporateleague.com/pcl_rest/api/v9/old-team-map-data/getAll',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING       => '',
        CURLOPT_MAXREDIRS      => 10,
        CURLOPT_TIMEOUT        => 8,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST  => 'GET',
    ));
    $response = curl_exec($curl);
    curl_close($curl);

    $teamInfo     = json_decode($response, true);
    $teamInfoData = [];
    if (!empty($teamInfo) && !empty($teamInfo['results']) && $teamInfo['code'] === 200) {
        foreach ($teamInfo['results'] as $key => $values) {
            if ($teamId == $values['team_id']) {
                $teamInfoData = $values;
                break;
            }
        }
    }

    // ── email: pehle requestData se, fallback teamInfoData se ──
    if (empty($email)) {
        $email = $teamInfoData['email'] ?? '';
    }
    $name = $profile['team_name'] ?? '';

    /* ── ALL CITIES ── */
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL            => 'https://www.procorporateleague.com/pcl_rest/api/v9/corporate/getAllCities',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING       => '',
        CURLOPT_MAXREDIRS      => 10,
        CURLOPT_TIMEOUT        => 8,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST  => 'GET',
    ));
    $response = curl_exec($curl);
    curl_close($curl);

    $getData  = json_decode($response, true);
    $cityData = [];
    if (!empty($getData) && !empty($getData['results']) && $getData['code'] === 200) {
        $cityData = $getData['results'] ?? [];
    }

    /* ── ALL SECTORS ── */
    $curl = curl_init();
    curl_setopt_array($curl, array(
        CURLOPT_URL            => 'https://www.procorporateleague.com/pcl_rest/api/v9/corporate/getAllSectors',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING       => '',
        CURLOPT_MAXREDIRS      => 10,
        CURLOPT_TIMEOUT        => 8,
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST  => 'GET',
    ));
    $response = curl_exec($curl);
    curl_close($curl);

    $getData    = json_decode($response, true);
    $sectorData = [];
    if (!empty($getData) && !empty($getData['results']) && $getData['code'] === 200) {
        $sectorData = $getData['results'] ?? [];
    }

    /* ── MATCH CITY & SECTOR ── */
    $singleCity   = [];
    $singleSector = [];

    if (!empty($teamInfoData) && is_array($teamInfoData)) {
        foreach ($cityData as $cityVal) {
            if (($teamInfoData['city'] ?? '') == $cityVal['id']) {
                $singleCity = $cityVal;
                break;
            }
        }

        foreach ($sectorData as $sectorVal) {
            if (($teamInfoData['sector'] ?? '') == $sectorVal['id']) {
                $singleSector = $sectorVal;
                break;
            }
        }
    }

    /* ── SMTP CREDENTIALS ── */
    $smtpSql = "SELECT * FROM `smtp_auth_data` WHERE id = 1";
    $smtpExe = mysqli_query($conn, $smtpSql);
    $smtpRow = mysqli_fetch_assoc($smtpExe);
    if (empty($smtpRow)) {
        echo json_encode(["status_code" => 400, "status" => "ERROR", "message" => "SMTP AUTH MISSING"]);
        die;
    }

    /* ===============================
       CXO-LEVEL DYNAMIC EMAIL TEMPLATE
       Corporate World Cup™ Invitation
    ================================ */

    $teamName   = trim((string)($profile['team_name'] ?? $teamInfoData['team_name'] ?? 'Your Team'));
    $cityName   = trim((string)($singleCity['city_name'] ?? $teamInfoData['city_name'] ?? 'Your City'));
    $sectorName = trim((string)($singleSector['name'] ?? $singleSector['sector_name'] ?? $teamInfoData['sector_name'] ?? 'Your Sector'));
    $safeTeam   = htmlspecialchars($teamName, ENT_QUOTES, 'UTF-8');
    $safeCity   = htmlspecialchars($cityName, ENT_QUOTES, 'UTF-8');
    $safeSector = htmlspecialchars($sectorName, ENT_QUOTES, 'UTF-8');

    $dashboardTeamId = trim((string)$teamId) !== '' ? (string)$teamId : ((strtoupper(trim((string)$teamName)) === 'TCS') ? '6147' : (string)$teamId);
    $teamDashboardUrl = 'https://www.procorporateleague.com/ai/corporate-cricket-team-ai-analysis/pcl-ai-corporate-team-profile.php?team_id=' . rawurlencode($dashboardTeamId) . '&team_name=' . rawurlencode($teamName);
    $reserveUrl       = 'https://www.procorporateleague.com/pcl/team-register/';
    $cwcUrl           = 'https://corporateworldcup.com/';
    $pclUrl           = 'https://www.procorporateleague.com/';

    $trophyImage      = 'https://wplspeedqueen.com/email_api/cwctrophy.png';
    $firechatImage    = 'https://wplspeedqueen.com/email_api/firechat.png';
    $merchandiseImage = 'https://wplspeedqueen.com/email_api/cwcmerchandise.jpeg';
    $pclLogo          = 'https://www.procorporateleague.com/2026/pcl/Imp_PCL_Logo_Black.png';
    $sonyLivLogo      = 'https://www.procorporateleague.com/2026/pcl/SonyLIV_2020.png';
    $cwcHeroImage     = 'https://www.roadtocorporateworldcup.com/assets/corporateworldcup.jpeg';
    $celebrityImage   = 'https://www.roadtocorporateworldcup.com/assets/PCLxCelebrity_Engagement.jpeg';
    $chrisGayleImage  = 'https://www.procorporateleague.com/uploads/sliders/mobile/images/20260603085928_Chris_Gayle_X_PCL__Slider_for_Mobile_.jpg';
    $championsVideo   = 'https://procorporateleague.com/assets/highlights/2025_Corporate_Champions.mp4';
    $sonyLivCoverageUrl = 'https://www.procorporateleague.com/pcl/media/pcl-eleven11-sony-liv-highlight/';

    $teamLogoRaw = trim((string)(
        $LogoUrl
        ?? $profile['team_logo']
        ?? $profile['logo']
        ?? $profile['company_logo']
        ?? $teamInfoData['team_logo']
        ?? $teamInfoData['logo']
        ?? $teamInfoData['company_logo']
        ?? ''
    ));

    if ($teamLogoRaw !== '' && !preg_match('/^https?:\/\//i', $teamLogoRaw)) {
        $teamLogoRaw = 'https://www.procorporateleague.com/2026/pcl/assets/team_logo/' . ltrim($teamLogoRaw, '/');
    }

    $teamLogoUrl = $teamLogoRaw !== '' ? $teamLogoRaw : $pclLogo;
    $teamLogoAlt = $safeTeam . ' Logo';

    ob_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Corporate World Cup™ Invitation | <?= $safeTeam ?></title>
</head>

<body style="margin:0;padding:0;background:#edf1f7;font-family:Arial,Helvetica,sans-serif;color:#17233c;">

<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:#edf1f7;">
<tr>
<td align="center" style="padding:22px 10px;">

<table role="presentation" width="900" cellpadding="0" cellspacing="0" border="0" style="width:900px;max-width:900px;background:#ffffff;border-radius:20px;overflow:hidden;border:1px solid #d8dfeb;">


<!-- TOP BRAND BAR -->
<tr>
<td style="background:#041432;padding:14px 24px;border-bottom:1px solid rgba(214,173,69,.45);">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td style="font-size:12px;line-height:1.5;color:#ffffff;">
        <strong>Subject:</strong> <?= $safeTeam ?> Has Been Shortlisted – Corporate World Cup™ Qualification Round
      </td>
      <td align="right" style="font-size:12px;line-height:1.5;">
        <a href="<?= $cwcUrl ?>" style="color:#ffffff;text-decoration:underline;">View in browser</a>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- GLOBAL HERO: WORLD CUP JOURNEY -->
<tr>
<td style="background:#071d46;padding:0;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" background="<?= $cwcHeroImage ?>" style="background-image:url('<?= $cwcHeroImage ?>');background-size:cover;background-position:center center;background-repeat:no-repeat;">
    <tr>
      <td style="padding:18px 24px 26px 24px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td width="39%" valign="top">
              <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:rgba(4,20,50,.90);border:1px solid rgba(214,173,69,.65);border-radius:18px;">
                <tr>
                  <td style="padding:18px 18px 20px 18px;">
                    <img src="<?= $teamLogoUrl ?>" width="120" alt="<?= $teamLogoAlt ?>" style="display:block;width:auto;max-width:120px;max-height:62px;height:auto;border:0;background:#ffffff;border-radius:10px;padding:10px;margin-bottom:18px;">

                    <div style="font-size:13px;line-height:1.5;color:#d6ad45;letter-spacing:2.3px;text-transform:uppercase;font-weight:700;">
                      Out Of 500+<br>Corporate Teams Evaluated
                    </div>

                    <div style="font-family:Georgia,'Times New Roman',serif;font-size:42px;line-height:1.05;color:#ffffff;font-weight:700;margin-top:12px;">
                      <?= $safeTeam ?>
                    </div>

                    <div style="font-size:15px;line-height:1.65;color:#ffffff;text-transform:uppercase;letter-spacing:.7px;margin-top:12px;">
                      Has Been Selected To Begin<br>
                      The Journey Towards The
                    </div>

                    <div style="font-family:Georgia,'Times New Roman',serif;font-size:25px;line-height:1.18;color:#d6ad45;font-weight:700;margin-top:12px;text-transform:uppercase;">
                      Inaugural<br>Corporate World Cup™<br>Championship
                    </div>

                    <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-top:22px;">
                      <tr>
                        <td width="25%" align="center" style="border-right:1px solid rgba(255,255,255,.20);padding:0 6px;">
                          <div style="font-size:22px;color:#d6ad45;">▣</div>
                          <div style="font-size:18px;color:#ffffff;font-weight:700;line-height:1.2;">15+</div>
                          <div style="font-size:10px;color:#ffffff;line-height:1.3;text-transform:uppercase;">Years</div>
                        </td>
                        <td width="25%" align="center" style="border-right:1px solid rgba(255,255,255,.20);padding:0 6px;">
                          <div style="font-size:22px;color:#d6ad45;">◎</div>
                          <div style="font-size:18px;color:#ffffff;font-weight:700;line-height:1.2;">500+</div>
                          <div style="font-size:10px;color:#ffffff;line-height:1.3;text-transform:uppercase;">Teams</div>
                        </td>
                        <td width="25%" align="center" style="border-right:1px solid rgba(255,255,255,.20);padding:0 6px;">
                          <div style="font-size:22px;color:#d6ad45;">🏏</div>
                          <div style="font-size:18px;color:#ffffff;font-weight:700;line-height:1.2;">3000+</div>
                          <div style="font-size:10px;color:#ffffff;line-height:1.3;text-transform:uppercase;">Matches</div>
                        </td>
                        <td width="25%" align="center" style="padding:0 6px;">
                          <div style="font-size:22px;color:#d6ad45;">🏆</div>
                          <div style="font-size:18px;color:#ffffff;font-weight:700;line-height:1.2;">1</div>
                          <div style="font-size:10px;color:#ffffff;line-height:1.3;text-transform:uppercase;">Global<br>Destination</div>
                        </td>
                      </tr>
                    </table>
                  </td>
                </tr>
              </table>
            </td>

            <td width="61%" valign="top" align="right" style="padding-left:16px;">
              <img src="<?= $sonyLivLogo ?>" width="82" alt="Sony LIV" style="display:block;width:82px;height:auto;border:0;border-radius:10px;margin:0 0 260px auto;background:#000000;">
            </td>
          </tr>
        </table>

        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-top:0;">
          <tr>
            <td align="center">
              <div style="display:inline-block;background:#d6ad45;color:#071d46;font-size:17px;line-height:1.2;font-weight:800;letter-spacing:.8px;text-transform:uppercase;padding:12px 34px;border-radius:10px 10px 0 0;">
                From Corporate Cricket To Corporate World Cup™
              </div>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- GLOBAL STORY STRIP -->
<tr>
<td style="background:#071d46;padding:16px 24px 10px 24px;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid rgba(214,173,69,.65);border-radius:16px;background:rgba(4,20,50,.78);">
    <tr>
      <td width="33.33%" valign="middle" style="padding:18px 18px;border-right:1px solid rgba(214,173,69,.45);">
        <table role="presentation" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td width="54" valign="top" style="font-size:34px;color:#d6ad45;">🌍</td>
            <td style="font-size:14px;line-height:1.65;color:#ffffff;">For more than a decade,<br>corporate teams have competed for city pride.</td>
          </tr>
        </table>
      </td>
      <td width="33.33%" valign="middle" style="padding:18px 18px;border-right:1px solid rgba(214,173,69,.45);">
        <table role="presentation" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td width="54" valign="top" style="font-size:34px;color:#d6ad45;">🏆</td>
            <td style="font-size:14px;line-height:1.65;color:#ffffff;">The Corporate World Cup™ creates something that has never existed before.</td>
          </tr>
        </table>
      </td>
      <td width="33.33%" valign="middle" style="padding:18px 18px;">
        <table role="presentation" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td width="54" valign="top" style="font-size:34px;color:#d6ad45;">🎯</td>
            <td style="font-size:14px;line-height:1.65;color:#ffffff;">A pathway towards becoming the first Corporate World Cup™ Champion.</td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- THE OPPORTUNITY OF A GENERATION -->
<tr>
<td style="background:#071d46;padding:8px 24px 10px 24px;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid rgba(214,173,69,.75);border-radius:18px;background:#061a40;">
    <tr>
      <td style="padding:24px 24px 10px 24px;text-align:center;">
        <div style="font-family:Georgia,'Times New Roman',serif;font-size:29px;line-height:1.2;color:#d6ad45;font-weight:700;text-transform:uppercase;letter-spacing:.8px;">
          The Opportunity Of A Generation
        </div>
      </td>
    </tr>
    <tr>
      <td style="padding:8px 24px 28px 24px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td width="62%" valign="top" style="padding-right:18px;">
              <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
                <tr>
                  <td width="33.33%" align="center" style="padding:6px;">
                    <div style="border:1px solid rgba(214,173,69,.45);border-radius:16px;padding:16px 10px;background:rgba(255,255,255,.04);min-height:92px;">
                      <div style="font-size:34px;color:#d6ad45;">🛡️</div>
                      <div style="font-size:13px;line-height:1.45;color:#ffffff;font-weight:700;text-transform:uppercase;"> <?= $safeTeam ?> Has<br>Won Matches.</div>
                    </div>
                  </td>
                  <td width="33.33%" align="center" style="padding:6px;">
                    <div style="border:1px solid rgba(214,173,69,.45);border-radius:16px;padding:16px 10px;background:rgba(255,255,255,.04);min-height:92px;">
                      <div style="font-size:34px;color:#d6ad45;">👥</div>
                      <div style="font-size:13px;line-height:1.45;color:#ffffff;font-weight:700;text-transform:uppercase;"> <?= $safeTeam ?> Has<br>Built Teams.</div>
                    </div>
                  </td>
                  <td width="33.33%" align="center" style="padding:6px;">
                    <div style="border:1px solid rgba(214,173,69,.45);border-radius:16px;padding:16px 10px;background:rgba(255,255,255,.04);min-height:92px;">
                      <div style="font-size:34px;color:#d6ad45;">🏅</div>
                      <div style="font-size:13px;line-height:1.45;color:#ffffff;font-weight:700;text-transform:uppercase;"> <?= $safeTeam ?> Has<br>Created Memories.</div>
                    </div>
                  </td>
                </tr>
              </table>

              <div style="font-size:14px;line-height:1.7;color:#ffffff;text-align:center;text-transform:uppercase;letter-spacing:.4px;margin-top:18px;">
                Now <?= $safeTeam ?> has the opportunity to compete for something<br>
                no corporate team has ever won.
              </div>

              <div style="font-family:Georgia,'Times New Roman',serif;font-size:33px;line-height:1.08;color:#ffffff;font-weight:700;margin-top:20px;">
                The Inaugural<br>
                <span style="color:#d6ad45;">Corporate World Cup™</span><br>
                Championship
              </div>
            </td>

            <td width="38%" valign="middle" style="padding-left:18px;border-left:1px solid rgba(214,173,69,.35);">
              <img src="<?= $trophyImage ?>" width="230" alt="Corporate World Cup Trophy" style="display:block;width:100%;max-width:230px;height:auto;border:0;margin:0 auto 18px auto;">
              <div style="font-size:15px;line-height:1.7;color:#ffffff;">
                “Years from now, many companies may participate in the Corporate World Cup™.”
              </div>
              <div style="font-size:16px;line-height:1.6;color:#d6ad45;font-weight:700;margin-top:14px;">
                History will remember the company that became the first champion.
              </div>
              <div style="font-family:Georgia,'Times New Roman',serif;font-size:22px;line-height:1.25;color:#ffffff;font-weight:700;margin-top:16px;">
                <?= $safeTeam ?> has the opportunity to become that company.
              </div>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- CORPORATE WORLD CUP LEGACY -->
<tr>
<td style="background:#071d46;padding:8px 24px 10px 24px;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid rgba(214,173,69,.75);border-radius:18px;background:#061a40;">
    <tr>
      <td style="padding:22px 24px 8px 24px;text-align:center;">
        <div style="display:inline-block;background:#d6ad45;color:#071d46;font-size:12px;letter-spacing:1.7px;text-transform:uppercase;padding:8px 14px;border-radius:999px;margin-bottom:12px;font-weight:700;">
          Corporate World Cup™ Legacy
        </div>
        <div style="font-family:Georgia,'Times New Roman',serif;font-size:31px;line-height:1.2;color:#ffffff;font-weight:700;">
          A Legacy That Begins Now
        </div>
      </td>
    </tr>
    <tr>
      <td style="padding:16px 20px 24px 20px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td width="25%" valign="top" align="center" style="padding:10px;border-right:1px solid rgba(214,173,69,.40);">
              <div style="font-size:32px;color:#d6ad45;">🛡️</div>
              <div style="font-size:13px;line-height:1.65;color:#ffffff;margin-top:8px;">For more than a decade, corporate teams across India have played, competed and represented their organizations with pride.</div>
            </td>
            <td width="25%" valign="top" align="center" style="padding:10px;border-right:1px solid rgba(214,173,69,.40);">
              <div style="font-size:32px;color:#d6ad45;">🏆</div>
              <div style="font-size:13px;line-height:1.65;color:#ffffff;margin-top:8px;">Many teams won city trophies. Many teams enjoyed successful seasons. Many teams built incredible cultures.</div>
            </td>
            <td width="25%" valign="top" align="center" style="padding:10px;border-right:1px solid rgba(214,173,69,.40);">
              <div style="font-size:32px;color:#d6ad45;">👑</div>
              <div style="font-size:13px;line-height:1.65;color:#ffffff;margin-top:8px;">But no corporate team has ever had the opportunity to become the inaugural Corporate World Cup™ Champion.</div>
            </td>
            <td width="25%" valign="top" align="center" style="padding:10px;">
              <div style="font-size:32px;color:#d6ad45;">🌐</div>
              <div style="font-size:13px;line-height:1.65;color:#ffffff;margin-top:8px;">Years from now, hundreds may participate. History will remember the teams that began the journey.</div>
            </td>
          </tr>
        </table>
        <div style="font-family:Georgia,'Times New Roman',serif;font-size:21px;line-height:1.5;color:#d6ad45;font-weight:700;text-align:center;margin-top:20px;">
          <?= $safeTeam ?> has the potential to become the inaugural Corporate World Cup™ Champion and create a lasting legacy in the world of corporate cricket.
        </div>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- 20% / FOUNDING 8 / HISTORY -->
<tr>
<td style="background:#071d46;padding:8px 24px 10px 24px;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td width="33.33%" valign="top" style="padding:0 5px 0 0;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid rgba(214,173,69,.75);border-radius:16px;background:#061a40;">
          <tr>
            <td style="padding:24px 20px;">
              <div style="font-family:Georgia,'Times New Roman',serif;font-size:31px;line-height:1.12;color:#ffffff;font-weight:700;">
                20% Cricket.<br><span style="color:#d6ad45;">80% Legacy.</span>
              </div>
              <div style="font-size:13px;line-height:1.85;color:#ffffff;margin-top:16px;">
                🏏 18 high-quality matches across 3 formats<br>
                🎥 Premium grounds, professional operations and live streaming<br>
                🏢 Build team culture, brand visibility and unforgettable memories
              </div>
              <div style="background:#d6ad45;color:#071d46;font-size:12px;line-height:1.45;font-weight:800;text-transform:uppercase;text-align:center;margin-top:18px;padding:12px;border-radius:8px;">
                For us, this isn't just cricket.<br>This is legacy in motion.
              </div>
            </td>
          </tr>
        </table>
      </td>

      <td width="33.33%" valign="top" style="padding:0 5px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid rgba(214,173,69,.75);border-radius:16px;background:#061a40;">
          <tr>
            <td align="center" style="padding:24px 20px;">
              <div style="font-family:Georgia,'Times New Roman',serif;font-size:24px;line-height:1.2;color:#d6ad45;font-weight:700;text-transform:uppercase;">The Founding 8™</div>
              <div style="font-family:Georgia,'Times New Roman',serif;font-size:92px;line-height:.95;color:#d6ad45;font-weight:700;margin:12px 0;">8</div>
              <div style="font-size:17px;line-height:1.65;color:#ffffff;font-weight:700;">
                Only 8 Teams Per City<br>
                Only 1 Team Per Sector<br>
                Only 2 Progress Further
              </div>
              <div style="background:#d6ad45;color:#071d46;font-size:14px;line-height:1.2;font-weight:800;text-transform:uppercase;margin-top:18px;padding:12px;border-radius:8px;">
                You Are One Of Them.
              </div>
            </td>
          </tr>
        </table>
      </td>

      <td width="33.33%" valign="top" style="padding:0 0 0 5px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid rgba(214,173,69,.75);border-radius:16px;background:#061a40;">
          <tr>
            <td style="padding:24px 20px;">
              <div style="font-family:Georgia,'Times New Roman',serif;font-size:25px;line-height:1.2;color:#d6ad45;font-weight:700;text-transform:uppercase;">Be Part Of History</div>
              <div style="font-size:14px;line-height:1.75;color:#ffffff;margin-top:12px;">
                As one of the handpicked 8 teams, <?= $safeTeam ?> will be part of the Founding 8™ and compete for the honor every corporate team will aspire to win.
              </div>
              <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-top:20px;">
                <tr>
                  <td width="33.33%" align="center" style="font-size:12px;line-height:1.45;color:#ffffff;">🏅<br>Legacy<br>Starts Now</td>
                  <td width="33.33%" align="center" style="font-size:12px;line-height:1.45;color:#ffffff;">🏆<br>Prestige That<br>Lasts</td>
                  <td width="33.33%" align="center" style="font-size:12px;line-height:1.45;color:#ffffff;">🏏<br>A Journey Your<br>Company Will Remember</td>
                </tr>
              </table>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- WHAT YOUR INVESTMENT CREATES -->
<tr>
<td style="padding:12px 28px;background:#ffffff;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid #e2e7f0;border-radius:18px;overflow:hidden;background:#ffffff;">
    <tr>
      <td style="background:#f7f9fc;padding:20px 24px;">
        <h2 style="margin:0;font-family:Georgia,'Times New Roman',serif;font-size:26px;line-height:1.2;color:#071d46;font-weight:700;">What Your Investment Creates</h2>
      </td>
    </tr>
    <tr>
      <td style="padding:20px 18px 22px 18px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size:14px;line-height:1.7;color:#24304a;">
          <tr>
            <td width="25%" valign="top" style="padding:6px;"><div style="border:1px solid #e2e7f0;border-radius:14px;padding:14px 12px;min-height:82px;">✅ <strong>30 Employee Ambassadors</strong><br><span style="color:#5d6880;font-size:12px;">Players become culture carriers.</span></div></td>
            <td width="25%" valign="top" style="padding:6px;"><div style="border:1px solid #e2e7f0;border-radius:14px;padding:14px 12px;min-height:82px;">✅ <strong>Employer Branding Assets</strong><br><span style="color:#5d6880;font-size:12px;">Stories, photos, highlights and team moments.</span></div></td>
            <td width="25%" valign="top" style="padding:6px;"><div style="border:1px solid #e2e7f0;border-radius:14px;padding:14px 12px;min-height:82px;">✅ <strong>Leadership Recognition</strong><br><span style="color:#5d6880;font-size:12px;">Visibility for captains, founders and HR leaders.</span></div></td>
            <td width="25%" valign="top" style="padding:6px;"><div style="border:1px solid #e2e7f0;border-radius:14px;padding:14px 12px;min-height:82px;">✅ <strong>Corporate Legacy</strong><br><span style="color:#5d6880;font-size:12px;">A place in the first qualification story.</span></div></td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- PARTICIPATION INCLUDES -->
<tr>
<td style="padding:12px 28px;background:#ffffff;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td width="58%" valign="top" style="padding-right:14px;">
        <div style="border:1px solid #e2e7f0;border-radius:18px;padding:22px 24px;">
          <h2 style="margin:0 0 16px 0;font-family:Georgia,'Times New Roman',serif;font-size:25px;line-height:1.2;color:#071d46;font-weight:700;">Participation Includes</h2>

          <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="font-size:14px;line-height:1.8;color:#24304a;">
            <tr><td style="padding:5px 0;">• 18 matches across three formats</td></tr>
            <tr><td style="padding:5px 0;">• Team merchandise for 30 players</td></tr>
            <tr><td style="padding:5px 0;">• Live match coverage and highlights</td></tr>
            <tr><td style="padding:5px 0;">• AI-powered team and player rankings</td></tr>
            <tr><td style="padding:5px 0;">• Corporate storytelling and employer branding opportunities</td></tr>
            <tr><td style="padding:5px 0;">• Eligibility to qualify for the Corporate World Cup™ National Finals ecosystem</td></tr>
          </table>
        </div>
      </td>

      <td width="42%" valign="top">
        <div style="border:1px solid #e2e7f0;border-radius:18px;overflow:hidden;background:#f7f9fc;">
          <img src="<?= $merchandiseImage ?>" width="340" alt="Corporate World Cup Team Merchandise" style="display:block;width:100%;height:auto;border:0;">
          <div style="padding:16px 18px;font-size:13px;line-height:1.7;color:#24304a;">
            30-player team merchandise package included as part of the qualification journey.
          </div>
        </div>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- FIRECHAT IMAGE BLOCK -->
<tr>
<td style="padding:12px 28px;background:#ffffff;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:#071d46;border-radius:18px;overflow:hidden;">
    <tr>
      <td width="48%" valign="middle" style="padding:24px;">
        <div style="font-size:12px;line-height:1.6;color:#d6ad45;letter-spacing:2px;text-transform:uppercase;">Invitation Included</div>
        <h2 style="margin:8px 0 10px 0;font-family:Georgia,'Times New Roman',serif;font-size:28px;line-height:1.2;color:#ffffff;font-weight:700;">Corporate World Cup™ Firechat</h2>
        <div style="font-size:15px;line-height:1.8;color:#eef4ff;">
          Featuring Sanath Jayasuriya and Anjum Chopra on 25 July 2026.
        </div>
      </td>
      <td width="52%" valign="middle" align="right">
        <img src="<?= $firechatImage ?>" width="460" alt="Corporate World Cup Firechat" style="display:block;width:100%;max-width:460px;height:auto;border:0;">
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- EXCLUSIVITY + QUALIFICATION -->
<tr>
<td style="padding:12px 28px;background:#ffffff;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td width="50%" valign="top" style="padding-right:7px;">
        <div style="border:1px solid #e2e7f0;border-radius:18px;padding:22px 24px;min-height:220px;">
          <h2 style="margin:0 0 14px 0;font-family:Georgia,'Times New Roman',serif;font-size:24px;line-height:1.2;color:#071d46;font-weight:700;">Category Exclusivity</h2>
          <div style="font-size:14px;line-height:1.8;color:#24304a;">
            As part of the Corporate World Cup™ structure, only one corporate team per sector is permitted in each city. This ensures category exclusivity throughout the qualification journey.
            <br><br>
            Once a sector is allocated, it is closed for the remainder of the qualification cycle.
          </div>
        </div>
      </td>
      <td width="50%" valign="top" style="padding-left:7px;">
        <div style="border:1px solid #e2e7f0;border-radius:18px;padding:22px 24px;min-height:220px;">
          <h2 style="margin:0 0 14px 0;font-family:Georgia,'Times New Roman',serif;font-size:24px;line-height:1.2;color:#071d46;font-weight:700;">Qualification Structure</h2>
          <div style="font-size:14px;line-height:1.9;color:#24304a;">
            • Only 8 corporate teams per city<br>
            • Only 1 corporate team per sector<br>
            • Top 2 city teams qualify for the Corporate World Cup™ National Finals ecosystem<br>
            • City champions receive complimentary entry into the National Finals structure
          </div>
        </div>
      </td>
    </tr>
  </table>
</td>
</tr>


<!-- CELEBRITY TRUST + PCL AUTHENTICITY -->
<tr>
<td style="padding:12px 28px;background:#ffffff;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid #e2e7f0;border-radius:18px;overflow:hidden;background:#071d46;">
    <tr>
      <td style="padding:24px 24px 12px 24px;">
        <div style="font-size:12px;line-height:1.6;color:#d6ad45;letter-spacing:2px;text-transform:uppercase;">Celebrity Trust & Corporate Credibility</div>
        <h2 style="margin:8px 0 10px 0;font-family:Georgia,'Times New Roman',serif;font-size:28px;line-height:1.2;color:#ffffff;font-weight:700;">15 Years Of Building Corporate Teams Beyond The Workplace</h2>
        <div style="font-size:14px;line-height:1.8;color:#eaf1ff;">
          Pro Corporate League has engaged 500+ corporate teams and worked alongside global cricket personalities to create one of India's most visible corporate cricket ecosystems.
        </div>
      </td>
    </tr>
    <tr>
      <td style="padding:10px 24px 0 24px;">
        <img src="<?= $celebrityImage ?>" width="852" alt="PCL Celebrity Engagement" style="display:block;width:100%;max-width:852px;height:auto;border:0;border-radius:14px;">
      </td>
    </tr>
    <tr>
      <td style="padding:14px 24px 24px 24px;font-size:13px;line-height:1.7;color:#dfe8ff;">
        A credibility-led ecosystem supported by cricket legends, corporate leaders and national-level corporate sporting stories.
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- CHRIS GAYLE AUTHENTICITY + CHAMPIONS VIDEO -->
<tr>
<td style="padding:12px 28px;background:#ffffff;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid #d6ad45;border-radius:18px;overflow:hidden;background:#fff8e4;">
    <tr>
      <td width="58%" valign="middle" style="padding:24px;">
        <div style="font-size:12px;line-height:1.6;color:#a17300;letter-spacing:2px;text-transform:uppercase;">PCL Season 11 Closing Ceremony</div>
        <h2 style="margin:8px 0 10px 0;font-family:Georgia,'Times New Roman',serif;font-size:26px;line-height:1.25;color:#071d46;font-weight:700;">Chris Gayle Presence Added Authenticity To The Corporate Champions Celebration</h2>
        <div style="font-size:14px;line-height:1.8;color:#24304a;">
          Chris Gayle was present during the PCL Season 11 closing ceremony, recognising corporate champions and strengthening the credibility of the Pro Corporate League ecosystem.
        </div>
      </td>
      <td width="42%" valign="middle" align="center" style="padding:18px;">
        <a href="<?= $championsVideo ?>" style="text-decoration:none;">
          <img src="<?= $chrisGayleImage ?>" width="330" alt="Chris Gayle at PCL Season 11 Closing Ceremony" style="display:block;width:100%;max-width:330px;height:auto;border:0;border-radius:14px;">
          <div style="display:inline-block;margin-top:12px;background:#071d46;color:#ffffff;font-size:12px;letter-spacing:.6px;text-transform:uppercase;padding:10px 16px;border-radius:999px;">Watch Champions Highlights</div>
        </a>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- SONY LIV AUTHENTICITY -->
<tr>
<td style="padding:12px 28px;background:#ffffff;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid #e2e7f0;border-radius:18px;overflow:hidden;background:#ffffff;">
    <tr>
      <td width="28%" valign="middle" align="center" style="padding:22px;background:#f7f9fc;">
        <img src="<?= $sonyLivLogo ?>" width="120" alt="Sony LIV" style="display:block;width:120px;max-width:120px;height:auto;border:0;margin:0 auto;">
      </td>
      <td width="72%" valign="middle" style="padding:22px;">
        <div style="font-size:12px;line-height:1.6;color:#a17300;letter-spacing:2px;text-transform:uppercase;">Broadcast Visibility</div>
        <h2 style="margin:8px 0 10px 0;font-family:Georgia,'Times New Roman',serif;font-size:25px;line-height:1.25;color:#071d46;font-weight:700;">PCL On Sony LIV</h2>
        <div style="font-size:14px;line-height:1.8;color:#24304a;">
          Pro Corporate League's Eleven 11 highlight property has been showcased through the Sony LIV ecosystem, adding broadcast credibility and visibility to participating corporate teams.
        </div>
        <div style="margin-top:14px;">
          <a href="<?= $sonyLivCoverageUrl ?>" style="display:inline-block;background:#071d46;color:#ffffff;text-decoration:none;font-size:12px;letter-spacing:.6px;text-transform:uppercase;padding:11px 17px;border-radius:999px;">View Sony LIV Coverage</a>
        </div>
      </td>
    </tr>
  </table>
</td>
</tr>


<!-- COMMERCIAL STRUCTURE -->
<tr>
<td style="background:#071d46;padding:8px 24px 10px 24px;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid rgba(214,173,69,.75);border-radius:16px;background:#061a40;">
    <tr>
      <td style="padding:22px 24px;text-align:center;">
        <div style="font-family:Georgia,'Times New Roman',serif;font-size:25px;line-height:1.25;color:#d6ad45;font-weight:700;text-transform:uppercase;">Commercial Structure</div>
        <div style="font-size:14px;line-height:1.7;color:#ffffff;margin-top:8px;">Corporate World Cup™ Qualification Package: <strong>₹5,00,000 + GST</strong></div>
      </td>
    </tr>
    <tr>
      <td style="padding:0 18px 22px 18px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td width="25%" style="padding:6px;">
              <div style="background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.16);border-radius:12px;padding:15px 10px;text-align:center;min-height:76px;">
                <div style="font-size:12px;color:#dfe8ff;line-height:1.5;">Advance Category Reservation</div>
                <div style="font-family:Georgia,'Times New Roman',serif;font-size:24px;color:#d6ad45;line-height:1.2;margin-top:7px;">₹2,00,000</div>
                <div style="font-size:11px;color:#dfe8ff;margin-top:4px;">+ GST</div>
              </div>
            </td>
            <td width="25%" style="padding:6px;">
              <div style="background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.16);border-radius:12px;padding:15px 10px;text-align:center;min-height:76px;">
                <div style="font-size:12px;color:#dfe8ff;line-height:1.5;">Before 31 Dec 2026</div>
                <div style="font-family:Georgia,'Times New Roman',serif;font-size:24px;color:#d6ad45;line-height:1.2;margin-top:7px;">₹2,00,000</div>
                <div style="font-size:11px;color:#dfe8ff;margin-top:4px;">+ GST</div>
              </div>
            </td>
            <td width="25%" style="padding:6px;">
              <div style="background:rgba(255,255,255,.06);border:1px solid rgba(255,255,255,.16);border-radius:12px;padding:15px 10px;text-align:center;min-height:76px;">
                <div style="font-size:12px;color:#dfe8ff;line-height:1.5;">Before 31 Mar 2027</div>
                <div style="font-family:Georgia,'Times New Roman',serif;font-size:24px;color:#d6ad45;line-height:1.2;margin-top:7px;">₹1,00,000</div>
                <div style="font-size:11px;color:#dfe8ff;margin-top:4px;">+ GST</div>
              </div>
            </td>
            <td width="25%" style="padding:6px;">
              <div style="background:#d6ad45;border:1px solid #d6ad45;border-radius:12px;padding:15px 10px;text-align:center;min-height:76px;">
                <div style="font-size:12px;color:#071d46;line-height:1.5;">Total Participation Fee</div>
                <div style="font-family:Georgia,'Times New Roman',serif;font-size:24px;color:#071d46;line-height:1.2;margin-top:7px;">₹5,00,000</div>
                <div style="font-size:11px;color:#071d46;margin-top:4px;">+ GST</div>
              </div>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- SECURE YOUR SPOT / ENDING -->
<tr>
<td style="background:#071d46;padding:8px 24px 18px 24px;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid rgba(214,173,69,.75);border-radius:16px;background:#061a40;">
    <tr>
      <td width="54%" valign="middle" style="padding:24px;border-right:1px solid rgba(214,173,69,.45);">
        <div style="font-family:Georgia,'Times New Roman',serif;font-size:27px;line-height:1.2;color:#d6ad45;font-weight:700;text-transform:uppercase;">Secure Your Spot</div>
        <div style="font-size:14px;line-height:1.75;color:#ffffff;margin-top:8px;">
          Confirm your participation and become part of the most prestigious corporate cricket journey ever. Let’s build history together.
        </div>
      </td>
      <td width="46%" valign="middle" align="center" style="padding:24px;">
        <a href="<?= $reserveUrl ?>" style="display:inline-block;background:#d6ad45;color:#071d46;text-decoration:none;font-family:Georgia,'Times New Roman',serif;font-size:18px;line-height:1.2;font-weight:700;text-transform:uppercase;padding:15px 44px;border-radius:8px;">Reserve Your Category</a>
        <div style="font-size:13px;line-height:1.7;color:#ffffff;margin-top:14px;">Only 8 Teams Per City • Only 1 Team Per Sector</div>
      </td>
    </tr>
  </table>
</td>
</tr>

<!-- CONTACT STRIP -->
<tr>
<td style="background:#041432;padding:18px 24px;border-top:1px solid rgba(214,173,69,.45);">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td align="center" style="font-size:13px;line-height:1.7;color:#ffffff;">☎ +91 76761 32328</td>
      <td align="center" style="font-size:13px;line-height:1.7;color:#ffffff;">✉ info@procorporateleague.com</td>
      <td align="center" style="font-size:13px;line-height:1.7;color:#ffffff;">🌐 www.procorporateleague.com</td>
    </tr>
  </table>
</td>
</tr>

<!-- FINAL FOOTER -->
<tr>
<td style="background:#ffffff;padding:20px 24px 24px 24px;text-align:center;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom:16px;">
    <tr>
      <td width="16.66%" align="center" valign="top" style="padding:6px;border-right:1px solid #d8dfeb;">
        <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;">Title Sponsor</div>
        <img src="<?= $teamLogoUrl ?>" width="82" alt="<?= $teamLogoAlt ?>" style="display:block;width:auto;max-width:82px;max-height:42px;height:auto;border:0;margin:8px auto 0 auto;">
      </td>
      <td width="16.66%" align="center" valign="top" style="padding:6px;border-right:1px solid #d8dfeb;">
        <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;">Broadcast Partner</div>
        <img src="<?= $sonyLivLogo ?>" width="62" alt="Sony LIV" style="display:block;width:62px;height:auto;border:0;border-radius:8px;margin:8px auto 0 auto;background:#000000;">
      </td>
      <td width="16.66%" align="center" valign="top" style="padding:6px;border-right:1px solid #d8dfeb;">
        <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;">Powered By</div>
        <div style="font-family:Georgia,'Times New Roman',serif;font-size:20px;color:#071d46;margin-top:12px;font-weight:700;">PCL</div>
      </td>
      <td width="16.66%" align="center" valign="top" style="padding:6px;border-right:1px solid #d8dfeb;">
        <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;">Media</div>
        <div style="font-size:13px;color:#071d46;margin-top:14px;font-weight:700;">Highlights</div>
      </td>
      <td width="16.66%" align="center" valign="top" style="padding:6px;border-right:1px solid #d8dfeb;">
        <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;">Legacy</div>
        <div style="font-size:13px;color:#071d46;margin-top:14px;font-weight:700;">15+ Years</div>
      </td>
      <td width="16.66%" align="center" valign="top" style="padding:6px;">
        <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;">Platform</div>
        <div style="font-size:13px;color:#071d46;margin-top:14px;font-weight:700;">AI Rankings</div>
      </td>
    </tr>
  </table>

  <div style="font-size:11px;line-height:1.8;color:#5d6880;">
    15+ Years Building Corporate Cricket • 500+ Corporate Teams • 3000+ Matches Conducted<br>
    Chris Gayle 2026 • Jonty Rhodes 2025 • PCL on Sony LIV<br>
    Pro Corporate League® • India's Corporate Cricket Ecosystem<br><br>
    <a href="<?= $teamDashboardUrl ?>" style="color:#071d46;text-decoration:none;">View Team Dashboard</a> &nbsp;|&nbsp;
    <a href="<?= $reserveUrl ?>" style="color:#071d46;text-decoration:none;">Reserve Category</a> &nbsp;|&nbsp;
    <a href="<?= $cwcUrl ?>" style="color:#071d46;text-decoration:none;">corporateworldcup.com</a><br>
    © 2026 Pro Corporate League. This communication is an official Corporate World Cup™ invitation for <?= $safeTeam ?>.
  </div>
</td>
</tr>
</table>

</td>
</tr>
</table>

</body>
</html>
<?php
$emailBody = ob_get_clean();

/* ===============================
   SEND EMAIL
================================ */
$mail = new PHPMailer(true);

$toName = $profile['team_name'] ?? '';

try {
    $mail->isSMTP();
    $mail->Host       = $smtpRow['smtp_host'];
    $mail->SMTPAuth   = true;
    $mail->Username   = $smtpRow['smtp_username'];
    $mail->Password   = $smtpRow['smtp_password'];
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
    $mail->Port       = 587;
    $mail->Timeout       = 15;    // ← add karo
    $mail->SMTPKeepAlive = true;  // ← add karo

    $mail->CharSet  = 'UTF-8';
    $mail->Encoding = 'base64';

    $mail->setFrom('sachin.gupta@procorporateleague.com', 'Pro Corporate League');

    $mail->addAddress($email, htmlspecialchars($toName));

    if (!empty($ccList) && is_array($ccList)) {
        foreach ($ccList as $cc) {
            $ccEmail = trim($cc['email'] ?? '');
            $ccName  = trim($cc['name']  ?? '');
            if (!empty($ccEmail)) {
                $mail->addCC($ccEmail, $ccName);
            }
        }
    } else {
        $mail->addCC('sachin.gupta@procorporateleague.com', 'Sachin Gupta');
        $mail->addCC('rifat.saleem@procorporateleague.com', 'Rifat Saleem');
        $mail->addCC('manvi.tanwar@procorporateleague.com', 'Manvi Tanwar');
    }

    $mail->isHTML(true);



   
    /* ── PDF ATTACHMENTS ── */
    $pdf1Path = __DIR__ . '/CorporateWorldCup_X_Team_Invitation.pdf';
    // $pdf2Path = __DIR__ . '/Team_Proposal.pdf'; 

    if (file_exists($pdf1Path)) {
        $mail->addAttachment($pdf1Path, 'PCL_CorporateWorldCup_X_Team_Invitation.pdf');
    }
    // if (file_exists($pdf2Path)) {
    //     $mail->addAttachment($pdf2Path, 'PCL_CWC_Document_2.pdf');
    // }
   /* ── END PDF ATTACHMENTS ── */






    $mail->Subject = !empty($requestData['subject'])
        ? $requestData['subject']
        : $safeTeam . ' Has Been Shortlisted For The Corporate World Cup™';

    $mail->Body = $emailBody;

    $mail->send();

    echo json_encode([
        "status_code" => 200,
        "status"      => "success",
        "message"     => "Email sent successfully"
    ]);

} catch (Exception $e) {
    echo json_encode([
        "status_code" => 500,
        "status"      => "error",
        "message"     => $mail->ErrorInfo,
        "debug"       => [
            "email"     => $email,
            "toName"    => $toName,
            "teamId"    => $teamId,
            "smtp_host" => $smtpRow['smtp_host'],
            "smtp_user" => $smtpRow['smtp_username'],
        ]
    ]);
}
?>