PHP code example of codeldev / laravel-mail-log

1. Go to this page and download the library: Download codeldev/laravel-mail-log library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

codeldev / laravel-mail-log example snippets


return [
    'prune_days' => (int) env('MAIL_LOG_PRUNE_DAYS', 365),
    'model' => CodelDev\LaravelMailLog\Models\LaravelMailLog::class,
    'table' => env('MAIL_LOG_TABLE', 'mail_log'),
];

Schedule::command('mail-log:prune')
    ->weeklyOn(1, '02:30')
    ->withoutOverlapping();

use CodelDev\LaravelMailLog\Models\LaravelMailLog;

// Get all logged emails
$emails = LaravelMailLog::all();

// Get emails sent to a specific address (not available for SQLite)
$emails = LaravelMailLog::query()
    ->whereJsonContains('to', '[email protected]')
    ->latest()
    ->get();

// Get emails sent today
$emails = LaravelMailLog::query()
    ->whereDate('created_at', today())
    ->get();

// Search by subject
$emails = LaravelMailLog::query()
    ->where('subject', 'like', '%Welcome%')
    ->latest()
    ->get();

use CodelDev\LaravelMailLog\Models\LaravelMailLog as BaseMailLog;

class MailLog extends BaseMailLog
{
    public function scopeToRecipient($query, string $email)
    {
        return $query->whereJsonContains('to', $email);
    }
}

'model' => \App\Models\MailLog::class,
bash
php artisan vendor:publish --tag="mail-log-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="mail-log-config"
dotenv
MAIL_LOG_PRUNE_DAYS=365
MAIL_LOG_TABLE=mail_log
bash
php artisan mail-log:prune