I am trying to figure out how I can send errors to my email in Laravel 5. I haven\'t had much luck finding any good resources.
There used to be good packages like: http
/config/logging.php
// ...
'monitoring-mail' => [
'driver' => 'custom',
'via' => App\Logging\Mail::class,
'level' => env('LOG_MONITORING_MAIL_LEVEL', 'error'),
'to' => env('LOG_MONITORING_TO'),
'from' => env('LOG_MONITORING_FROM'),
],
// ...
/app/Logging/Mail.php
/app/Helpers/Log/MailHandler.php
to = $to;
$this->config = (array) $config;
}
protected function write(array $record): void
{
$body = $record['formatted'] ?? $record['message'] ?? '';
Mail::raw($body, function (Message $message) use ($record) {
$subject = ($record['level_name'] ?? 'ERROR') . ': ' . ($record['message'] ?? '');
$message->to($this->to);
$message->subject($subject);
if (!empty($this->config['from'])) {
$message->from($this->config['from']);
}
});
}
}