From f54f198879bf05b9eaeff59205e92b5558161726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Pocrnji=C4=8D?= Date: Sat, 18 Oct 2025 19:53:23 +0200 Subject: [PATCH] Fixed attachemnts not working on production --- app/Services/EmailSender.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/app/Services/EmailSender.php b/app/Services/EmailSender.php index cdf5050..7f00ba9 100644 --- a/app/Services/EmailSender.php +++ b/app/Services/EmailSender.php @@ -186,9 +186,35 @@ public function sendFromLog(EmailLog $log): array } $name = $att['name'] ?? basename($path); $mime = $att['mime'] ?? 'application/octet-stream'; - $full = \Storage::disk($disk)->path($path); - if (is_file($full)) { - $email->attachFromPath($full, $name, $mime); + + $attached = false; + $storage = \Storage::disk($disk); + // Prefer local path when available (local driver) + try { + if (method_exists($storage, 'path')) { + $full = $storage->path($path); + if (is_string($full) && is_file($full)) { + $email->attachFromPath($full, $name, $mime); + $attached = true; + } + } + } catch (\Throwable $e) { + // fall through to bytes + } + + if (! $attached) { + // Fallback for non-local disks (e.g., S3): read bytes and attach directly + try { + if ($storage->exists($path)) { + $bytes = $storage->get($path); + if (! is_null($bytes) && $bytes !== false) { + $email->attach($bytes, $name, $mime); + $attached = true; + } + } + } catch (\Throwable $e) { + // ignore, continue to next attachment + } } } catch (\Throwable $e) { // ignore individual attachment failures; continue sending