Changes to documents able to edit them now, also support for auto mail attechemnts
This commit is contained in:
@@ -149,14 +149,14 @@ public function sendFromLog(EmailLog $log): array
|
||||
if ($singleTo === '' || ! filter_var($singleTo, FILTER_VALIDATE_EMAIL)) {
|
||||
throw new \InvalidArgumentException('No valid recipient email found for EmailLog #'.$log->id);
|
||||
}
|
||||
$email->to(new Address($singleTo, (string) ($log->to_name ?? '')));
|
||||
$email->to(new Address($singleTo, (string) ($log->to_name ?? '')));
|
||||
}
|
||||
|
||||
// Always BCC the sender mailbox if present and not already in To
|
||||
$senderBcc = null;
|
||||
if ($fromAddr !== '' && filter_var($fromAddr, FILTER_VALIDATE_EMAIL)) {
|
||||
// Check duplicates against toList
|
||||
$lowerTo = array_map(fn($v) => strtolower(trim((string) $v)), (array) ($log->to_recipients ?? [$log->to_email]));
|
||||
$lowerTo = array_map(fn ($v) => strtolower(trim((string) $v)), (array) ($log->to_recipients ?? [$log->to_email]));
|
||||
if (! in_array(strtolower($fromAddr), $lowerTo, true)) {
|
||||
$senderBcc = $fromAddr;
|
||||
$email->bcc(new Address($senderBcc));
|
||||
@@ -175,6 +175,26 @@ public function sendFromLog(EmailLog $log): array
|
||||
$email->replyTo($log->reply_to);
|
||||
}
|
||||
|
||||
// Attach files if present on the log
|
||||
$attachments = (array) ($log->attachments ?? []);
|
||||
foreach ($attachments as $att) {
|
||||
try {
|
||||
$disk = $att['disk'] ?? 'public';
|
||||
$path = $att['path'] ?? null;
|
||||
if (! $path) {
|
||||
continue;
|
||||
}
|
||||
$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);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
// ignore individual attachment failures; continue sending
|
||||
}
|
||||
}
|
||||
|
||||
$mailer->send($email);
|
||||
// Save log if we modified BCC
|
||||
if (! empty($log->getAttribute('bcc'))) {
|
||||
@@ -205,7 +225,7 @@ public function sendFromLog(EmailLog $log): array
|
||||
// BCC the sender mailbox if resolvable and not already in To
|
||||
$fromAddr = (string) ($log->from_email ?: (config('mail.from.address') ?? ''));
|
||||
if ($fromAddr !== '' && filter_var($fromAddr, FILTER_VALIDATE_EMAIL)) {
|
||||
$lowerTo = array_map(fn($v) => strtolower(trim((string) $v)), (array) ($log->to_recipients ?? [$log->to_email]));
|
||||
$lowerTo = array_map(fn ($v) => strtolower(trim((string) $v)), (array) ($log->to_recipients ?? [$log->to_email]));
|
||||
if (! in_array(strtolower($fromAddr), $lowerTo, true)) {
|
||||
$message->bcc($fromAddr);
|
||||
$log->bcc = [$fromAddr];
|
||||
@@ -240,7 +260,7 @@ public function sendFromLog(EmailLog $log): array
|
||||
// BCC the sender mailbox if resolvable and not already in To
|
||||
$fromAddr = (string) ($log->from_email ?: (config('mail.from.address') ?? ''));
|
||||
if ($fromAddr !== '' && filter_var($fromAddr, FILTER_VALIDATE_EMAIL)) {
|
||||
$lowerTo = array_map(fn($v) => strtolower(trim((string) $v)), (array) ($log->to_recipients ?? [$log->to_email]));
|
||||
$lowerTo = array_map(fn ($v) => strtolower(trim((string) $v)), (array) ($log->to_recipients ?? [$log->to_email]));
|
||||
if (! in_array(strtolower($fromAddr), $lowerTo, true)) {
|
||||
$message->bcc($fromAddr);
|
||||
$log->bcc = [$fromAddr];
|
||||
|
||||
Reference in New Issue
Block a user