EmailLog Model
The EmailLog model tracks all transactional email sends for audit and debugging.
Table: email_logs
Model: App\Models\EmailLog
Database Schema
| Column | Type | Nullable | Description |
|---|---|---|---|
id | bigint unsigned | No | Primary key |
correlation_id | varchar(255) | No | Request correlation ID (indexed) |
provider | varchar(255) | No | Email provider (mailgun, mailjet, etc.) |
driver | varchar(255) | No | Mail driver |
from_email | varchar(255) | No | Sender address |
to_email | varchar(255) | No | Recipient address |
subject | varchar(255) | No | Email subject |
status | enum | No | queued (default), sent, delivered, bounced, failed |
provider_message_id | varchar(255) | Yes | Provider tracking ID |
error_message | text | Yes | Failure reason |
metadata | json | Yes | Provider response metadata |
sent_at | timestamp | Yes | When sent |
created_at | timestamp | Yes | |
updated_at | timestamp | Yes |
Indexes: email_logs_correlation_id_index (correlation_id) and email_logs_lookup_idx (provider, status, created_at).
Constants
EmailLog::STATUS_QUEUED
EmailLog::STATUS_SENT
EmailLog::STATUS_DELIVERED
EmailLog::STATUS_BOUNCED
EmailLog::STATUS_FAILED
Scopes
EmailLog::successful() // status sent or delivered
EmailLog::failed()
EmailLog::forProvider($provider)
EmailLog::forCorrelation($correlationId)
EmailLog::recent($days = 7) // created_at within the last $days days
Usage Notes
- Email logs are not scoped by organization; they are platform-wide.
- Status updates are written by the transactional email service.
- Rows older than
RETENTION_EMAIL_LOGS_DAYS(default 90) are pruned daily bymodel:prune(PrunesByRetention).