@php $company = config('company'); $brand = $company['brand']; $logoCfg = $company['logo']; $preheader = $preheader ?? ''; $heading = $heading ?? null; $footerNote = $footerNote ?? null; // Prefer CID-embedded logo when a Mailable is rendering the view; fall // back to an absolute URL for stand-alone renders (e.g. Mail::send with // raw ->html($bodyHtml)). Never emit a localhost URL — Gmail's image // proxy would 404 it — and never emit a broken-file URL. // // Order of preference: // 1. CID embed via $message->embed() (works everywhere, no external // fetch, does not depend on APP_URL). Requires the view to be // rendered through the mailer (Mail::send with a view name, or a // Mailable). Pre-rendering with view()->render() skips this. // 2. COMPANY_LOGO_URL env override — an absolute HTTPS URL the admin // pins for public delivery (CDN, S3, etc.). Bypasses APP_URL. // 3. APP_URL + logo path when APP_URL is a real public URL. // If none resolve, the header shows the company name text as a mark. // Resolution order: // 1. Explicit $embeddedLogo passed in (controllers that pre-embed via // $message->embed() inside the Mail::send callback and pass the // resulting cid: string in as a view variable — required whenever // the view is pre-rendered with view()->render() before the mailer // creates $message). // 2. CID embed via $message->embed() — works when the view is rendered // by the mailer itself (Mailable using Content(view: ...) or // Mail::send with a view name). // 3. COMPANY_LOGO_URL env — absolute HTTPS URL the admin pins. // 4. APP_URL + logo path, only when APP_URL is a real public URL. // If none resolve, the header shows the company name text as a mark. // Load the admin-configured Email Logo (Settings → Company → Email // Logo). Only one row in `settings` — id 1 — carries the config; we // read it once here and let it drive resolution below. $adminEmailLogo = null; $adminEmailLogoWidth = null; try { $adminSetting = \App\Models\Setting::find(1); if ($adminSetting) { $sourceType = strtolower((string) ($adminSetting->email_logo_source_type ?? '')); $adminEmailLogoWidth = (int) ($adminSetting->email_logo_width ?? 0) ?: null; if ($sourceType === 'upload' && !empty($adminSetting->email_logo_path)) { $adminEmailLogo = ['type' => 'upload', 'value' => $adminSetting->email_logo_path]; } elseif ($sourceType === 'url' && !empty($adminSetting->email_logo_url)) { $adminEmailLogo = ['type' => 'url', 'value' => $adminSetting->email_logo_url]; } } } catch (\Throwable $e) { /* fall through to bundled fallback */ } // Resolution order: // 1. Admin-configured Email Logo (upload path preferred as CID; URL // used as-is when it's absolute https). // 2. Explicit $embeddedLogo view variable (legacy pre-embed pattern). // 3. Bundled circular-logo CID embed via $message->embed(). // 4. COMPANY_LOGO_URL env fallback. // 5. APP_URL + logo path (skipped on localhost). // If none resolve, the header shows the company name text as a mark. $logoSrc = null; $logoFile = public_path($logoCfg['path']); // (1) Admin-configured Email Logo. if ($adminEmailLogo) { if ($adminEmailLogo['type'] === 'upload') { $absPath = public_path(ltrim($adminEmailLogo['value'], '/')); try { if (isset($message) && is_object($message) && method_exists($message, 'embed') && is_file($absPath) && filesize($absPath) > 0) { $logoSrc = $message->embed($absPath); } } catch (\Throwable $e) { /* fall through */ } if (!$logoSrc) { // Non-mailer render — build the absolute URL from APP_URL // when non-local so the image is at least fetchable. $appUrl = rtrim((string) config('app.url'), '/'); $isLocal = $appUrl === '' || preg_match('~^https?://(localhost|127\.0\.0\.1|::1)~i', $appUrl); if (!$isLocal) { $logoSrc = $appUrl . '/' . ltrim($adminEmailLogo['value'], '/'); } } } elseif ($adminEmailLogo['type'] === 'url' && preg_match('~^https://~i', $adminEmailLogo['value']) && !preg_match('~^https?://(localhost|127\.0\.0\.1|::1)~i', $adminEmailLogo['value'])) { $logoSrc = $adminEmailLogo['value']; } } // (2) Legacy view variable pre-embed. if (!$logoSrc && !empty($embeddedLogo) && is_string($embeddedLogo)) { $logoSrc = $embeddedLogo; } // (3) Bundled circular-logo CID embed. if (!$logoSrc) { try { if (isset($message) && is_object($message) && method_exists($message, 'embed')) { if (is_file($logoFile) && filesize($logoFile) > 0) { $logoSrc = $message->embed($logoFile); } } } catch (\Throwable $e) { /* fall through */ } } // (4) COMPANY_LOGO_URL env override. if (!$logoSrc) { $envUrl = trim((string) config('company.logo.public_url', env('COMPANY_LOGO_URL', ''))); if ($envUrl !== '' && preg_match('~^https?://~i', $envUrl)) { $logoSrc = $envUrl; } } // (5) APP_URL + bundled logo path (skip localhost). if (!$logoSrc) { $appUrl = rtrim((string) config('app.url'), '/'); $isLocal = $appUrl === '' || preg_match('~^https?://(localhost|127\.0\.0\.1|::1)~i', $appUrl); if (!$isLocal) { $logoSrc = $appUrl . '/' . ltrim($logoCfg['path'], '/'); } } // Effective width — admin-configured overrides the config default, // then clamped to the 180–320px range. If the admin value is // missing, out of range, or the config default itself is invalid, // fall back to 260px so the logo is always clearly visible. $DEFAULT_LOGO_WIDTH = 260; $MIN_LOGO_WIDTH = 180; $MAX_LOGO_WIDTH = 320; $effectiveLogoWidth = $DEFAULT_LOGO_WIDTH; if ($adminEmailLogoWidth && $adminEmailLogoWidth > 0) { $effectiveLogoWidth = max($MIN_LOGO_WIDTH, min($MAX_LOGO_WIDTH, (int) $adminEmailLogoWidth)); } else { $configured = (int) ($logoCfg['width'] ?? 0); if ($configured >= $MIN_LOGO_WIDTH && $configured <= $MAX_LOGO_WIDTH) { $effectiveLogoWidth = $configured; } } @endphp {{ $company['short'] }} {{-- Preheader (hidden preview text) --}} @if($preheader)
{{ $preheader }}
@endif
{{-- HEADER --}} {{-- BODY --}} {{-- SUMMARY --}} @hasSection('summary') @endif {{-- CTA --}} @hasSection('cta') @endif {{-- FOOTER NOTE --}} @hasSection('footerNote') @else @if($footerNote) @endif @endif {{-- FOOTER --}}