<?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);

    

    if (!is_array($requestData)) {
        $requestData = [];
    }

    /* ── ENTERPRISE EMAIL TRACKING HELPERS ── */
    function pclEnterprisePostJson($url, array $payload)
    {
        $ch = curl_init($url);
        curl_setopt_array($ch, [
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_POST           => true,
            CURLOPT_POSTFIELDS     => json_encode($payload, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
            CURLOPT_HTTPHEADER     => ['Content-Type: application/json'],
            CURLOPT_TIMEOUT        => 10,
            CURLOPT_CONNECTTIMEOUT => 5,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
        ]);

        $response = curl_exec($ch);
        $error    = curl_error($ch);
        $httpCode = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);

        return [
            'tracking_status' => ($error === '' && $httpCode >= 200 && $httpCode < 300) ? 'success' : 'failed',
            'http_code'       => $httpCode,
            'response'        => $response,
            'error'           => $error,
            'url'             => $url,
        ];
    }

    function pclTrackTeamInvitationEmail(array $payload)
    {
        $apiBase = 'https://www.procorporateleague.com/pcl_rest/api/v15';
        return pclEnterprisePostJson($apiBase . '/email/track/legacy-call', $payload);
    }

    function pclCurrentRequestUrl()
    {
        $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
        $host   = $_SERVER['HTTP_HOST'] ?? 'wplspeedqueen.com';
        $uri    = $_SERVER['REQUEST_URI'] ?? ($_SERVER['SCRIPT_NAME'] ?? '/email_api/teamInvitationEmail.php');
        return $scheme . '://' . $host . $uri;
    }

    function pclPublicUrlForSameFolder($fileName)
    {
        $scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
        $host   = $_SERVER['HTTP_HOST'] ?? 'wplspeedqueen.com';
        $script = $_SERVER['SCRIPT_NAME'] ?? '/email_api/teamInvitationEmail.php';
        $dir    = rtrim(str_replace('\\', '/', dirname($script)), '/');
        return $scheme . '://' . $host . $dir . '/' . ltrim($fileName, '/');
    }

    function pclBuildCallingFileUrl(array $requestData, $teamId)
    {
        foreach ([
            'calling_file_url',
            'calling_page_url',
            'parent_page_url',
            'source_url',
            'admin_page_url',
            'source_page_url',
            'referrer_url',
            'referer_url'
        ] as $key) {
            if (!empty($requestData[$key])) {
                return $requestData[$key];
            }
        }

        if (!empty($_SERVER['HTTP_REFERER'])) {
            return $_SERVER['HTTP_REFERER'];
        }

        $teamName = $requestData['teamName'] ?? ($requestData['team_name'] ?? ($requestData['company_name'] ?? ''));
        $query = http_build_query([
            'team_id'  => $teamId,
            'teamName' => $teamName
        ]);

        return 'https://procorporateleague.com/2026/admin/pcl-lead-management/team-invitation.php' . ($query ? '?' . $query : '');
    }

    $emailAttachments = [];
    $attachmentUrls   = [];
    $attachmentCount  = 0;
    $trackingResult   = null;
$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;">
  <!-- Header hero image area: image fitted 100% before the gold ribbon, no crop -->
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" background="<?= $cwcHeroImage ?>" style="background-image:url('<?= $cwcHeroImage ?>');background-size:100% auto;background-position:center top;background-repeat:no-repeat;background-color:#071d46;">
    <tr>
      <td style="padding:26px 24px 0 24px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td width="45%" valign="top">
              <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:rgba(4,20,50,.91);border:1px solid rgba(214,173,69,.75);border-radius:18px;">
                <tr>
                  <td style="padding:24px 22px 24px 22px;">
                    <img src="<?= $teamLogoUrl ?>" width="120" alt="<?= $teamLogoAlt ?>" style="display:block;width:auto;max-width:120px;max-height:58px;height:auto;border:0;background:#ffffff;border-radius:10px;padding:9px;margin-bottom:18px;">

                    <div style="font-size:13px;line-height:1.55;color:#d6ad45;letter-spacing:2.4px;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:16px;line-height:1.55;color:#ffffff;text-transform:uppercase;letter-spacing:.6px;margin-top:12px;">
                      Has Been Selected To Begin<br>
                      The Journey Towards
                    </div>

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

            <td width="55%" valign="top" align="right" style="padding-left:16px;">
              <div style="font-size:1px;line-height:1px;height:315px;">&nbsp;</div>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>

  <!-- Ribbon sits after the fully visible hero image -->
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:#071d46;">
    <tr>
      <td align="center" style="padding:0 24px 0 24px;">
	   <div style="font-family:Georgia,'Times New Roman',serif;font-size:27px;line-height:1.12;color:#d6ad45;font-weight:700;margin-top:0;text-transform:uppercase;">
                      Inaugural<br>Corporate World Cup™<br>Championship
                    </div>
        <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:14px 42px;border-radius:10px 10px 0 0;">
          From Corporate Cricket To Corporate World Cup™
        </div>
      </td>
    </tr>
  </table>

  <!-- Legacy stat bar moved below ribbon -->
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:#071d46;">
    <tr>
      <td style="padding:12px 24px 18px 24px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:rgba(4,20,50,.84);border:1px solid rgba(214,173,69,.72);border-radius:14px;">
          <tr>
            <td width="25%" align="center" style="padding:16px 12px;border-right:1px solid rgba(214,173,69,.45);">
              <table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center">
                <tr>
                  <td valign="middle" style="font-size:30px;color:#d6ad45;padding-right:12px;">▣</td>
                  <td valign="middle" align="left">
                    <div style="font-size:28px;color:#ffffff;font-weight:800;line-height:1;">15+</div>
                    <div style="font-size:12px;color:#ffffff;line-height:1.3;text-transform:uppercase;letter-spacing:.5px;">Years Of Legacy</div>
                  </td>
                </tr>
              </table>
            </td>
            <td width="25%" align="center" style="padding:16px 12px;border-right:1px solid rgba(214,173,69,.45);">
              <table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center">
                <tr>
                  <td valign="middle" style="font-size:30px;color:#d6ad45;padding-right:12px;">●●</td>
                  <td valign="middle" align="left">
                    <div style="font-size:28px;color:#ffffff;font-weight:800;line-height:1;">500+</div>
                    <div style="font-size:12px;color:#ffffff;line-height:1.3;text-transform:uppercase;letter-spacing:.5px;">Corporate Teams</div>
                  </td>
                </tr>
              </table>
            </td>
            <td width="25%" align="center" style="padding:16px 12px;border-right:1px solid rgba(214,173,69,.45);">
              <table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center">
                <tr>
                  <td valign="middle" style="font-size:30px;color:#d6ad45;padding-right:12px;">🏏</td>
                  <td valign="middle" align="left">
                    <div style="font-size:28px;color:#ffffff;font-weight:800;line-height:1;">3000+</div>
                    <div style="font-size:12px;color:#ffffff;line-height:1.3;text-transform:uppercase;letter-spacing:.5px;">Matches Conducted</div>
                  </td>
                </tr>
              </table>
            </td>
            <td width="25%" align="center" style="padding:16px 12px;">
              <table role="presentation" cellpadding="0" cellspacing="0" border="0" align="center">
                <tr>
                  <td valign="middle" style="font-size:30px;color:#d6ad45;padding-right:12px;">🏆</td>
                  <td valign="middle" align="left">
                    <div style="font-size:28px;color:#ffffff;font-weight:800;line-height:1;">1</div>
                    <div style="font-size:12px;color:#ffffff;line-height:1.3;text-transform:uppercase;letter-spacing:.5px;">Global Destination</div>
                  </td>
                </tr>
              </table>
            </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>


<!-- SHORTLISTED TROPHY SECTION WITH DASHBOARD CTA -->
<!--tr>
<td style="background:#071d46;padding:34px 30px 36px 30px;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td width="58%" valign="middle" style="padding-right:24px;">
        <div style="font-size:12px;line-height:1.6;color:#d6ad45;letter-spacing:2px;text-transform:uppercase;margin-bottom:12px;">The Opportunity Of A Generation</div>

        <h1 style="margin:0;font-family:Georgia,'Times New Roman',serif;font-size:44px;line-height:1.08;color:#ffffff;font-weight:700;">
          <?= $safeTeam ?> Has Been Shortlisted
        </h1>

        <div style="margin-top:16px;font-size:12px;line-height:1.6;color:#eef4ff;">
         
        </div>
		<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="margin-top:22px;padding:14px 16px;background:rgba(255,255,255,.08);border:1px solid rgba(214,173,69,.45);border-radius:14px;color:#ffffff;font-size:14px;line-height:1.7;">
          Now <?= $safeTeam ?> has the opportunity to compete for something no corporate team has ever won.

The Inaugural Corporate World Cup™ Championship.
        </div>

        <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-top:24px;">
          <tr>
            <td style="padding-right:10px;">
              <a href="<?= $teamDashboardUrl ?>" style="display:inline-block;background:#d6ad45;color:#071d46;text-decoration:none;font-size:13px;letter-spacing:.6px;text-transform:uppercase;padding:13px 20px;border-radius:999px;font-weight:700;">View Team Dashboard</a>
            </td>
            <td>
              <a href="<?= $reserveUrl ?>" style="display:inline-block;border:1px solid #d6ad45;color:#ffffff;text-decoration:none;font-size:13px;letter-spacing:.6px;text-transform:uppercase;padding:12px 20px;border-radius:999px;font-weight:700;">Reserve Category</a>
            </td>
          </tr>
        </table>
      </td>

      <td width="42%" valign="middle" align="center">
        <div style="background:#ffffff;border-radius:18px;padding:18px 18px 20px 18px;border:1px solid rgba(214,173,69,.55);">
          <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom:14px;">
            <tr>
              <td align="left" valign="middle" style="width:50%;">
                <img src="<?= $teamLogoUrl ?>" width="120" alt="<?= $teamLogoAlt ?>" style="display:block;width:auto;max-width:120px;max-height:50px;height:auto;border:0;object-fit:contain;">
              </td>
              <td align="right" valign="middle" style="width:50%;">
                <img src="<?= $sonyLivLogo ?>" width="82" alt="Sony LIV" style="display:block;width:auto;max-width:82px;max-height:40px;height:auto;border:0;object-fit:contain;border-radius:8px;background:#000000;">
              </td>
            </tr>
          </table>

          <img src="<?= $trophyImage ?>" width="300" alt="Corporate World Cup Trophy" style="display:block;width:100%;max-width:300px;height:auto;border:0;margin:0 auto;object-fit:contain;">

          <div style="font-size:12px;line-height:1.6;color:#071d46;margin-top:10px;">
            Only 2 teams from <?= $safeCity ?> will qualify for the National Finals ecosystem.
          </div>
        </div>
      </td>
    </tr>
  </table>
</td>
</tr-->



<!-- THE OPPORTUNITY OF A GENERATION -->
<tr>
<td style="background:#071d46;padding:14px 28px 18px 28px;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid rgba(214,173,69,.85);border-radius:20px;background:#061a40;overflow:hidden;">
    <tr>
      <td style="padding:26px 26px 8px 26px;text-align:center;">
        <div style="font-family:Georgia,'Times New Roman',serif;font-size:32px;line-height:1.15;color:#d6ad45;font-weight:700;text-transform:uppercase;letter-spacing:1px;">
          The Opportunity Of A Generation
        </div>
      </td>
    </tr>

    <tr>
      <td style="padding:10px 28px 30px 28px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0">
          <tr>
            <td width="64%" valign="middle" style="padding-right:28px;">

              <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,.55);border-radius:15px;padding:16px 9px;background:rgba(255,255,255,.05);min-height:98px;">
                      <div style="font-size:34px;color:#d6ad45;line-height:1;">🛡️</div>
                      <div style="font-size:13px;line-height:1.45;color:#ffffff;font-weight:700;text-transform:uppercase;margin-top:8px;"> <?= $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,.55);border-radius:15px;padding:16px 9px;background:rgba(255,255,255,.05);min-height:98px;">
                      <div style="font-size:34px;color:#d6ad45;line-height:1;">👥</div>
                      <div style="font-size:13px;line-height:1.45;color:#ffffff;font-weight:700;text-transform:uppercase;margin-top:8px;"> <?= $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,.55);border-radius:15px;padding:16px 9px;background:rgba(255,255,255,.05);min-height:98px;">
                      <div style="font-size:34px;color:#d6ad45;line-height:1;">🏅</div>
                      <div style="font-size:13px;line-height:1.45;color:#ffffff;font-weight:700;text-transform:uppercase;margin-top:8px;"> <?= $safeTeam ?> Has<br>Created Memories.</div>
                    </div>
                  </td>
                </tr>
              </table>

              <div style="font-size:15px;line-height:1.7;color:#ffffff;text-align:center;text-transform:uppercase;letter-spacing:.35px;margin-top:20px;">
                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:38px;line-height:1.06;color:#ffffff;font-weight:700;margin-top:18px;text-align:left;">
                The Inaugural<br>
                <span style="color:#d6ad45;">Corporate World Cup™</span><br>
                Championship
              </div>

              <table role="presentation" cellpadding="0" cellspacing="0" border="0" style="margin-top:24px;">
                <tr>
                  <td style="padding-right:12px;">
                    <a href="<?= $teamDashboardUrl ?>" style="display:inline-block;background:#d6ad45;color:#071d46;text-decoration:none;font-size:13px;letter-spacing:.6px;text-transform:uppercase;padding:13px 22px;border-radius:999px;font-weight:700;">View Team Dashboard</a>
                  </td>
                  <td>
                    <a href="<?= $reserveUrl ?>" style="display:inline-block;border:1px solid #d6ad45;color:#ffffff;text-decoration:none;font-size:13px;letter-spacing:.6px;text-transform:uppercase;padding:12px 22px;border-radius:999px;font-weight:700;">Reserve Category</a>
                  </td>
                </tr>
              </table>

            </td>

            <td width="36%" valign="middle" align="center" style="padding-left:18px;border-left:1px solid rgba(214,173,69,.35);">
              <div style="background:#ffffff;border-radius:18px;padding:18px 18px 18px 18px;border:1px solid rgba(214,173,69,.65);">
                <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom:12px;">
                  <tr>
                    <td align="left" valign="middle" style="width:50%;">
                      <img src="<?= $teamLogoUrl ?>" width="105" alt="<?= $teamLogoAlt ?>" style="display:block;width:auto;max-width:105px;max-height:44px;height:auto;border:0;object-fit:contain;">
                    </td>
                    <td align="right" valign="middle" style="width:50%;">
                      <img src="<?= $sonyLivLogo ?>" width="72" alt="Sony LIV" style="display:block;width:auto;max-width:72px;max-height:36px;height:auto;border:0;object-fit:contain;border-radius:8px;background:#000000;">
                    </td>
                  </tr>
                </table>

                <img src="<?= $trophyImage ?>" width="245" alt="Corporate World Cup Trophy" style="display:block;width:100%;max-width:245px;height:auto;border:0;margin:0 auto;object-fit:contain;">

                <div style="font-size:12px;line-height:1.6;color:#071d46;margin-top:10px;text-align:center;">
                  Only 2 teams from <?= $safeCity ?> will qualify for the National Finals ecosystem.
                </div>
              </div>
            </td>
          </tr>
        </table>
      </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;">
        #TheUniverseBoss Chris Gayle joined the PCL Season 11 Closing Ceremony to celebrate corporate champions, adding global sporting recognition and further strengthening the credibility, prestige, and legacy 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>

<!-- 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>



<!-- 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:#071d46;padding:0 22px 26px 22px;text-align:center;">
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background:#ffffff;border-radius:0 0 22px 22px;overflow:hidden;border-top:4px solid #d6ad45;">
    <tr>
      <td style="padding:24px 18px 16px 18px;text-align:center;">
        <div style="font-family:Georgia,'Times New Roman',serif;font-size:24px;line-height:1.25;color:#071d46;font-weight:700;margin-bottom:8px;">
          Corporate World Cup™ Ecosystem
        </div>
        <div style="font-size:12px;line-height:1.7;color:#5d6880;">
          15+ Years Building Corporate Cricket • 500+ Corporate Teams • 3000+ Matches Conducted
        </div>
      </td>
    </tr>

    <tr>
      <td style="padding:0 18px 18px 18px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="border:1px solid #d8dfeb;border-radius:16px;overflow:hidden;">
          <tr>
            <td width="14.28%" align="center" valign="middle" style="padding:16px 8px;border-right:1px solid #d8dfeb;background:#fbfcff;">
              <a href="<?= $teamDashboardUrl ?>" style="text-decoration:none;color:#071d46;">
                <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;letter-spacing:.7px;">Your Sector</div>
                <img src="<?= $teamLogoUrl ?>" width="82" alt="<?= $teamLogoAlt ?>" style="display:block;width:auto;max-width:82px;max-height:42px;height:auto;border:0;margin:9px auto 8px auto;">
                <div style="font-size:12px;line-height:1.35;color:#071d46;font-weight:700;"><?= $safeSector ?></div>
              </a>
            </td>

            <td width="14.28%" align="center" valign="middle" style="padding:16px 8px;border-right:1px solid #d8dfeb;background:#ffffff;">
              <a href="https://www.procorporateleague.com/pcl/media/pcl-eleven11-sony-liv-highlight/" style="text-decoration:none;color:#071d46;">
                <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;letter-spacing:.7px;">OTT Partner</div>
                <img src="<?= $sonyLivLogo ?>" width="62" alt="Sony LIV" style="display:block;width:62px;height:auto;border:0;border-radius:8px;margin:9px auto 8px auto;background:#000000;">
                <div style="font-size:12px;line-height:1.35;color:#071d46;font-weight:700;">Sony LIV</div>
              </a>
            </td>

            <td width="14.28%" align="center" valign="middle" style="padding:16px 8px;border-right:1px solid #d8dfeb;background:#fbfcff;">
              <a href="https://www.procorporateleague.com/" style="text-decoration:none;color:#071d46;">
                <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;letter-spacing:.7px;">Powered By</div>
                <img src="<?= $pclLogo ?>" width="78" alt="Pro Corporate League" style="display:block;width:auto;max-width:78px;max-height:42px;height:auto;border:0;margin:9px auto 8px auto;">
                <div style="font-size:12px;line-height:1.35;color:#071d46;font-weight:700;">PCL</div>
              </a>
            </td>

            <td width="14.28%" align="center" valign="middle" style="padding:16px 8px;border-right:1px solid #d8dfeb;background:#ffffff;">
              <a href="https://www.procorporateleague.com/pcl/media/pcl-corporate-cricket-electronic-media-coverage/" style="text-decoration:none;color:#071d46;">
                <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;letter-spacing:.7px;">Media</div>
                <div style="font-size:28px;line-height:1;margin:9px 0 8px 0;">🎥</div>
                <div style="font-size:12px;line-height:1.35;color:#071d46;font-weight:700;">Highlights</div>
              </a>
            </td>

            <td width="14.28%" align="center" valign="middle" style="padding:16px 8px;border-right:1px solid #d8dfeb;background:#fbfcff;">
              <a href="https://www.procorporateleague.com/pcl/media/pcl-legacy-corporate-cricket-india/" style="text-decoration:none;color:#071d46;">
                <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;letter-spacing:.7px;">Legacy</div>
                <div style="font-size:28px;line-height:1;margin:9px 0 8px 0;">🏆</div>
                <div style="font-size:12px;line-height:1.35;color:#071d46;font-weight:700;">15+ Years</div>
              </a>
            </td>

            <td width="14.28%" align="center" valign="middle" style="padding:16px 8px;border-right:1px solid #d8dfeb;background:#ffffff;">
              <a href="https://www.procorporateleague.com/ai/corporate-cricket-rankings-india" style="text-decoration:none;color:#071d46;">
                <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;letter-spacing:.7px;">Platform</div>
                <div style="font-size:28px;line-height:1;margin:9px 0 8px 0;">📊</div>
                <div style="font-size:12px;line-height:1.35;color:#071d46;font-weight:700;">AI Rankings</div>
              </a>
            </td>

            <td width="14.28%" align="center" valign="middle" style="padding:16px 8px;background:#fbfcff;">
              <a href="https://www.procorporateleague.com/pcl/media/pcl-eleven11-sony-liv-highlight/" style="text-decoration:none;color:#071d46;">
                <div style="font-size:10px;line-height:1.4;color:#5d6880;text-transform:uppercase;letter-spacing:.7px;">On Sony LIV</div>
                <div style="font-size:28px;line-height:1;margin:9px 0 8px 0;">📺</div>
                <div style="font-size:12px;line-height:1.35;color:#071d46;font-weight:700;">PCL on Sony LIV</div>
              </a>
            </td>
          </tr>
        </table>
      </td>
    </tr>

    <tr>
      <td style="padding:6px 24px 8px 24px;text-align:center;">
        <div style="font-size:12px;line-height:2;color:#5d6880;">
          <a href="https://corporateworldcup.com/" style="color:#d6ad45;text-decoration:none;font-weight:700;">corporateworldcup.com</a>
          &nbsp;|&nbsp;
          <a href="https://www.roadtocorporateworldcup.com/" style="color:#d6ad45;text-decoration:none;font-weight:700;">roadtocorporateworldcup.com</a>
          <br>
          <a href="https://www.procorporateleague.com/pcl/media/chris-gayle-universe-boss-corporate-cricket-india/" style="color:#d6ad45;text-decoration:none;">Chris Gayle at PCL</a>
          &nbsp;|&nbsp;
          <a href="https://www.procorporateleague.com/pcl/media/jonty-rhodes-goat-pcl-corporate-cricket-india/" style="color:#d6ad45;text-decoration:none;">Jonty Rhodes at PCL</a>
          &nbsp;|&nbsp;
          <a href="https://www.procorporateleague.com/pcl/media/pcl-legacy-corporate-cricket-india/" style="color:#d6ad45;text-decoration:none;">PCL Legacy</a>
          <br>
          <a href="https://www.procorporateleague.com/pcl/media/pcl-print-media-coverage-corporate-cricket-india/" style="color:#d6ad45;text-decoration:none;">Print Media</a>
          &nbsp;|&nbsp;
          <a href="https://www.procorporateleague.com/pcl/media/pcl-corporate-cricket-electronic-media-coverage/" style="color:#d6ad45;text-decoration:none;">Electronic Media</a>
          &nbsp;|&nbsp;
          <a href="https://www.procorporateleague.com/pcl/media/pcl-eleven11-sony-liv-highlight/" style="color:#d6ad45;text-decoration:none;">PCL on Sony LIV</a>
          &nbsp;|&nbsp;
          <a href="https://www.procorporateleague.com/ai/pcl-ai-sports-tech-platform/" style="color:#d6ad45;text-decoration:none;">PCL AI Sports Tech</a>
          &nbsp;|&nbsp;
          <a href="https://www.procorporateleague.com/ai/corporate-cricket-rankings-india" style="color:#d6ad45;text-decoration:none;">Corporate Cricket Rankings</a>
        </div>
      </td>
    </tr>

    <tr>
      <td style="padding:14px 24px 18px 24px;text-align:center;border-top:1px solid #e7ebf3;">
        <div style="font-size:12px;line-height:1.9;color:#071d46;">
          <a href="<?= $teamDashboardUrl ?>" style="color:#071d46;text-decoration:none;font-weight:700;">View Team Dashboard</a>
          &nbsp;|&nbsp;
          <a href="<?= $reserveUrl ?>" style="color:#071d46;text-decoration:none;font-weight:700;">Reserve Category</a>
          &nbsp;|&nbsp;
          <a href="<?= $cwcUrl ?>" style="color:#071d46;text-decoration:none;font-weight:700;">corporateworldcup.com</a>
          <br>
          <a href="mailto:pcl@procorporateleague.com" style="color:#071d46;text-decoration:none;">pcl@procorporateleague.com</a>
          <br>
          <span style="color:#5d6880;">© 2026 Pro Corporate League. This communication is an official Corporate World Cup™ invitation for <?= $safeTeam ?>.</span>
        </div>
      </td>
    </tr>
  </table>
</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 + DB AUDIT METADATA ── */
    $emailAttachments = [];

    $pdf1Path = __DIR__ . '/CorporateWorldCup_X_Team_Invitation.pdf';
    $pdf1Name = 'PCL_CorporateWorldCup_X_Team_Invitation.pdf';
    $pdf1Url  = pclPublicUrlForSameFolder('CorporateWorldCup_X_Team_Invitation.pdf');

    if (file_exists($pdf1Path)) {
        $mail->addAttachment($pdf1Path, $pdf1Name);

        $emailAttachments[] = [
            'file_name'   => $pdf1Name,
            'url'         => $pdf1Url,
            'server_path' => $pdf1Path,
            'mime_type'   => 'application/pdf',
            'type'        => 'pdf',
            'size_bytes'  => filesize($pdf1Path),
            'disposition' => 'attachment'
        ];
    }

    $attachmentUrls = array_values(array_filter(array_map(function ($item) {
        return $item['url'] ?? null;
    }, $emailAttachments)));

    $attachmentCount = count($emailAttachments);
   /* ── END PDF ATTACHMENTS + DB AUDIT METADATA ── */






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

    $mail->Body = $emailBody;

    /* ── FINAL RENDERED EMAIL + URL AUDIT PAYLOAD ── */
    $currentEmailUrl = pclCurrentRequestUrl(); // actual current API/PHP URL
    $directEmailUrl  = pclPublicUrlForSameFolder('teamInvitationEmail.php'); // direct public email file URL
    $callingFileUrl  = pclBuildCallingFileUrl($requestData, $teamId); // admin/source page URL
    $serverFullPath  = __FILE__;
    $requestUri      = $_SERVER['REQUEST_URI'] ?? '';
    $scriptName      = $_SERVER['SCRIPT_NAME'] ?? '';
    $parentDomain    = $_SERVER['HTTP_HOST'] ?? 'wplspeedqueen.com';

    $trackingBasePayload = [
        'active_file_name'    => 'teamInvitationEmail.php',
        'email_file'          => 'teamInvitationEmail.php',
        'template_file'       => 'teamInvitationEmail.php',
        'module_key'          => $requestData['module_key']    ?? 'team_invitation',
        'submodule_key'       => $requestData['submodule_key'] ?? 'team_invitation_email',

        'lead_id'             => $requestData['lead_id'] ?? null,
        'team_id'             => $teamId,
        'user_id'             => $requestData['user_id'] ?? null,

        'recipient_email'     => $email,
        'recipient_name'      => $toName,
        'recipient_mobile'    => $requestData['mobile'] ?? ($teamInfoData['mobile'] ?? ''),
        'cc'                  => !empty($ccList) ? implode(',', array_column($ccList, 'email')) : 'sachin.gupta@procorporateleague.com,rifat.saleem@procorporateleague.com,manvi.tanwar@procorporateleague.com',
        'bcc'                 => '',
        'cc_json'             => json_encode($ccList, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
        'bcc_json'            => json_encode([], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),

        'sender_name'         => 'Pro Corporate League',
        'sender_email'        => 'sachin.gupta@procorporateleague.com',
        'reply_to_email'      => 'sachin.gupta@procorporateleague.com',

        'subject'             => $mail->Subject,
        'preheader'           => $requestData['preheader'] ?? '',
        'full_email_html'     => $mail->Body, // final actual client email after dynamic values are replaced
        'full_email_text'     => trim(preg_replace('/\s+/', ' ', strip_tags($mail->Body))),
        'html_length'         => strlen($mail->Body),

        'attachment_urls'     => implode(',', $attachmentUrls),
        'attachments_json'    => json_encode($emailAttachments, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
        'attachment_count'    => $attachmentCount,

        'current_email_url'   => $currentEmailUrl,
        'direct_email_url'    => $directEmailUrl,
        'calling_file_url'    => $callingFileUrl,
        'public_calling_url'  => $currentEmailUrl,
        'calling_page_url'    => $callingFileUrl,
        'parent_page_url'     => $callingFileUrl,
        'source_url'          => $callingFileUrl,
        'server_full_path'    => $serverFullPath,
        'server_file_path'    => $serverFullPath,
        'request_uri'         => $requestUri,
        'script_name'         => $scriptName,

        'parent_domain'       => $parentDomain,
        'parent_project'      => 'PCL Email API',
        'parent_page_name'    => 'Existing Team Invitation Sender',
        'source_type'         => 'legacy_direct_url',
        'source_key'          => 'team_invitation_email',
        'email_category'      => 'team_invitation',
        'email_event'         => 'corporate_world_cup_team_invitation',
        'journey_entity_type' => 'team',
        'journey_entity_id'   => $teamId,
        'journey_stage'       => 'team_invitation_email',
        'trigger_name'        => 'team_invitation_send',
        'send_mode'           => 'legacy_file',

        'request_payload'     => json_encode($requestData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
        'request_payload_json'=> json_encode($requestData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
        'payload_json'        => json_encode($requestData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
        'sent_at'             => date('Y-m-d H:i:s')
    ];

    $mail->send();

    $providerMessageId = method_exists($mail, 'getLastMessageID') ? $mail->getLastMessageID() : '';

    $trackingResult = pclTrackTeamInvitationEmail(array_merge($trackingBasePayload, [
        'status'              => 'sent',
        'delivery_status'     => 'sent',
        'provider_message_id' => $providerMessageId,
        'error_message'       => '',
        'response_json'       => json_encode([
            'phpmailer_status'     => 'sent',
            'provider_message_id'  => $providerMessageId,
            'html_length'          => strlen($mail->Body),
            'attachment_count'     => $attachmentCount,
            'attachment_urls'      => $attachmentUrls
        ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
    ]));

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

} catch (Exception $e) {
    $failedSubject = !empty($mail->Subject)
        ? $mail->Subject
        : (($safeTeam ?? 'Team') . ' Has Been Shortlisted For The Corporate World Cup™');

    $currentEmailUrl = function_exists('pclCurrentRequestUrl') ? pclCurrentRequestUrl() : '';
    $directEmailUrl  = function_exists('pclPublicUrlForSameFolder') ? pclPublicUrlForSameFolder('teamInvitationEmail.php') : '';
    $callingFileUrl  = function_exists('pclBuildCallingFileUrl') ? pclBuildCallingFileUrl($requestData, $teamId) : '';
    $serverFullPath  = __FILE__;

    $trackingResult = pclTrackTeamInvitationEmail([
        'active_file_name'    => 'teamInvitationEmail.php',
        'email_file'          => 'teamInvitationEmail.php',
        'template_file'       => 'teamInvitationEmail.php',
        'module_key'          => $requestData['module_key']    ?? 'team_invitation',
        'submodule_key'       => $requestData['submodule_key'] ?? 'team_invitation_email',
        'lead_id'             => $requestData['lead_id'] ?? null,
        'team_id'             => $teamId,
        'recipient_email'     => $email,
        'recipient_name'      => $toName ?? '',
        'recipient_mobile'    => $requestData['mobile'] ?? ($teamInfoData['mobile'] ?? ''),
        'sender_name'         => 'Pro Corporate League',
        'sender_email'        => 'sachin.gupta@procorporateleague.com',
        'subject'             => $failedSubject,
        'full_email_html'     => !empty($mail->Body) ? $mail->Body : '',
        'full_email_text'     => !empty($mail->Body) ? trim(preg_replace('/\s+/', ' ', strip_tags($mail->Body))) : '',
        'html_length'         => !empty($mail->Body) ? strlen($mail->Body) : 0,

        'attachment_urls'     => isset($attachmentUrls) ? implode(',', $attachmentUrls) : '',
        'attachments_json'    => isset($emailAttachments) ? json_encode($emailAttachments, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) : '[]',
        'attachment_count'    => isset($attachmentCount) ? $attachmentCount : 0,

        'current_email_url'   => $currentEmailUrl,
        'direct_email_url'    => $directEmailUrl,
        'calling_file_url'    => $callingFileUrl,
        'public_calling_url'  => $currentEmailUrl,
        'calling_page_url'    => $callingFileUrl,
        'parent_page_url'     => $callingFileUrl,
        'source_url'          => $callingFileUrl,
        'server_full_path'    => $serverFullPath,
        'request_uri'         => $_SERVER['REQUEST_URI'] ?? '',
        'script_name'         => $_SERVER['SCRIPT_NAME'] ?? '',
        'parent_domain'       => $_SERVER['HTTP_HOST'] ?? 'wplspeedqueen.com',
        'parent_project'      => 'PCL Email API',
        'parent_page_name'    => 'Existing Team Invitation Sender',
        'source_type'         => 'legacy_direct_url',
        'source_key'          => 'team_invitation_email',
        'email_category'      => 'team_invitation',
        'email_event'         => 'corporate_world_cup_team_invitation',
        'journey_entity_type' => 'team',
        'journey_entity_id'   => $teamId,
        'journey_stage'       => 'team_invitation_email',
        'trigger_name'        => 'team_invitation_send',
        'send_mode'           => 'legacy_file',
        'request_payload'     => json_encode($requestData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
        'request_payload_json'=> json_encode($requestData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
        'payload_json'        => json_encode($requestData, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
        'status'              => 'failed',
        'delivery_status'     => 'failed',
        'error_message'       => $mail->ErrorInfo ?: $e->getMessage(),
        'response_json'       => json_encode([
            'phpmailer_status' => 'failed',
            'phpmailer_error'  => $mail->ErrorInfo,
            'exception'        => $e->getMessage()
        ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE),
        'sent_at'             => date('Y-m-d H:i:s')
    ]);

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