Pixelairport's avatar

Looking for a transactional mailable plugin (with ui or filament)

Like in my question Im looking for a plugin, where I can setup mails with an UI like:

Send an email to all users, who dont login last 3 months. And send another email, if the user does not click the email in 1 week.

This is just an example. I already watched videos about spatie mailcoach, which looks good. But it seems I also have to setup a lot in the code, when I want to add extra logic with events.

0 likes
2 replies
LaryAI's avatar
Level 58

To achieve the functionality you're looking for, you can use a combination of Laravel's built-in features and some additional packages. While there might not be a single plugin that does everything out-of-the-box with a UI, you can piece together a solution using Laravel's scheduling, notifications, and possibly a package like Spatie's Mailcoach for more advanced email marketing features.

Here's a step-by-step approach:

  1. User Query for Inactivity: Use Eloquent to query users who haven't logged in for the last 3 months.

    use App\Models\User;
    use Carbon\Carbon;
    
    $inactiveUsers = User::where('last_login_at', '<', Carbon::now()->subMonths(3))->get();
    
  2. Send Emails: Use Laravel's Mailable to send emails to these users.

    use Illuminate\Support\Facades\Mail;
    use App\Mail\InactivityReminder;
    
    foreach ($inactiveUsers as $user) {
        Mail::to($user->email)->send(new InactivityReminder($user));
    }
    
  3. Track Email Opens: To track if a user has opened an email, you can use a package like Laravel Mail Tracker or integrate with a service that provides open tracking.

  4. Schedule Follow-up Emails: Use Laravel's task scheduling to send follow-up emails if the user hasn't opened the email within a week.

    // In App\Console\Kernel.php
    protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            $users = User::where('last_login_at', '<', Carbon::now()->subMonths(3))
                         ->whereDoesntHave('emailOpens', function ($query) {
                             $query->where('created_at', '>', Carbon::now()->subWeek());
                         })->get();
    
            foreach ($users as $user) {
                Mail::to($user->email)->send(new FollowUpReminder($user));
            }
        })->weekly();
    }
    
  5. UI for Managing Emails: While there isn't a direct UI for managing transactional emails in Laravel, you can build a simple admin panel using Laravel Filament or Nova to manage and view email campaigns, user activity, and more.

  6. Consider Spatie Mailcoach: If you need more advanced features like detailed analytics, segmentation, and automation, Spatie Mailcoach is a great option. It does require some setup, but it provides a robust platform for email marketing.

By combining these tools and techniques, you can create a system that sends transactional emails based on user activity and follows up as needed. While it requires some coding, it gives you the flexibility to customize the logic to fit your specific needs.

Pixelairport's avatar

Ok, this answer also does the extra logic in code. Maybe it is the best way, to do all in the code. I think to do it with an ui could be very complex. Then I simple do it like everytime in the code.

Please or to participate in this conversation.