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