73 lines
2.3 KiB
PHP
73 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Mail;
|
|
|
|
use App\Models\Mailing;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Mail\Mailable;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class MailingErrorMail extends Mailable
|
|
{
|
|
use Queueable, SerializesModels;
|
|
|
|
public Mailing $mailing;
|
|
public string $errorMessage;
|
|
public string $locale;
|
|
public int $recipientCount;
|
|
|
|
public function __construct(Mailing $mailing, string $errorMessage, string $locale = '', int $recipientCount = 0)
|
|
{
|
|
$this->mailing = $mailing;
|
|
$this->errorMessage = $errorMessage;
|
|
$this->locale = $locale;
|
|
$this->recipientCount = $recipientCount;
|
|
}
|
|
|
|
public function build(): self
|
|
{
|
|
$mailing = $this->mailing;
|
|
|
|
$subject = '[' . config('app.name') . '] Mailing failed: ' . $mailing->title;
|
|
|
|
$lines = [];
|
|
$lines[] = 'Mailing Error Report: ' . $mailing->title;
|
|
$lines[] = str_repeat('-', 40);
|
|
$lines[] = '';
|
|
$lines[] = 'Status: Failed';
|
|
if ($mailing->sending_started_at) {
|
|
$lines[] = 'Started sending: ' . $mailing->sending_started_at->format('d M Y H:i');
|
|
}
|
|
$lines[] = 'Failed at: ' . now()->format('d M Y H:i');
|
|
if ($this->locale) {
|
|
$lines[] = 'Locale (batch): ' . strtoupper($this->locale);
|
|
}
|
|
if ($this->recipientCount > 0) {
|
|
$lines[] = 'Recipients in batch: ' . number_format($this->recipientCount);
|
|
}
|
|
$lines[] = '';
|
|
$lines[] = 'Recipients: ' . number_format($mailing->recipients_count);
|
|
$lines[] = 'Successfully sent: ' . number_format($mailing->sent_count);
|
|
$lines[] = 'Failed: ' . number_format($mailing->failed_count);
|
|
$lines[] = 'Skipped (bounced): ' . number_format($mailing->skipped_count);
|
|
$lines[] = '';
|
|
$lines[] = str_repeat('-', 40);
|
|
$lines[] = 'Error Details';
|
|
$lines[] = str_repeat('-', 40);
|
|
$lines[] = '';
|
|
|
|
// Wrap long error lines
|
|
foreach (explode("\n", $this->errorMessage) as $line) {
|
|
$lines[] = $line;
|
|
}
|
|
|
|
$lines[] = '';
|
|
$lines[] = str_repeat('-', 40);
|
|
$lines[] = config('app.name');
|
|
|
|
return $this->subject($subject)->text('emails.mailing-error-plain', [
|
|
'lines' => $lines,
|
|
]);
|
|
}
|
|
}
|