NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

->to() is additive and accepts an email/route string, a CampaignRecipient, a contacts-for-laravel Contact record, a HasContacts owner model, or any iterable of those — an array, a collection or a generator:

use Illuminate\Support\Str;
use RoundlyConsulting\Campaigns\CampaignRecipient;
use RoundlyConsulting\Campaigns\Facades\Campaigns;

Campaigns::create('Our spring collection is here', $html)
    ->from('[email protected]', 'Example Shop')
    ->to('[email protected]')                          // one address or route
    ->to(['[email protected]', '[email protected]'])    // any iterable — calls are additive
    ->to(new CampaignRecipient(                      // full control over the id and name
        uuid: (string) Str::uuid(),
        name: 'Dana Novak',
        reachableAt: '[email protected]',
    ))
    ->dispatch();
  • A plain string becomes a recipient whose name and address are both that string, with a generated UUID.
  • A CampaignRecipient is kept as-is — use it to set a display name or your own id.
  • Each address is added once: one already on the campaign — compared case-insensitively, however it arrives (a string, a CampaignRecipient, an owner or a contact) — is skipped, and the first one added wins. A model recipient is de-duplicated by its model instead.
  • A recipient that already belongs to another campaign is added as a fresh copy — new uuid, clean delivery state, model and meta kept — and never moved out of the campaign it came from.
  • Anything else — a number, or a model without the HasContacts trait — throws InvalidArgumentException.

Contact records and owners have their own rules — see Recipients from contacts.

Large lists

For big audiences, stream the source query instead of loading it at once: lazyById() reads the table in chunks, and to() accepts the lazy collection like any other iterable. Every recipient is stored when the campaign is prepared, and start() then dispatches one job per stored recipient:

use App\Models\Subscriber;
use Illuminate\Support\Str;
use RoundlyConsulting\Campaigns\CampaignRecipient;
use RoundlyConsulting\Campaigns\Facades\Campaigns;

$campaign = Campaigns::create('Monthly digest', $html)
    ->from('[email protected]', 'Example Shop')
    ->to(Subscriber::query()->lazyById(500)->map(fn (Subscriber $subscriber) => new CampaignRecipient(
        uuid: (string) Str::uuid(),
        name: $subscriber->name,
        reachableAt: $subscriber->email,
    )))
    ->prepare();

Campaigns::start($campaign);   // one job per stored recipient

Collect the whole audience before prepare() or dispatch() — start() queues the recipients stored at that moment.

Model recipients

A recipient can stand for one of your models — a User, a Member — instead of, or as well as, an address. Your delivery job then reaches that person the way your app already does, and the campaign still tracks who was reached:

use App\Models\User;
use RoundlyConsulting\Campaigns\CampaignRecipient;
use RoundlyConsulting\Campaigns\Facades\Campaigns;

Campaigns::create('Office closed Friday', $html)
    ->to($users->map(fn (User $user) => CampaignRecipient::forModel(
        $user,
        $user->name,
        meta: ['locale' => $user->locale],   // host data, stored and handed back, never read
    )))
    ->dispatch();

// With an address as well — the shipped email and notification jobs can deliver to it:
CampaignRecipient::forModel($user, $user->name, reachableAt: $user->email);
  • forModel($model, $name, ?$reachableAt, ?$meta) stores the model’s morph class (getMorphClass()) and key; an unsaved model throws InvalidArgumentException.
  • A recipient is an address, a model, or both. Without a model reachableAt is required; a model needs both its type and its id.
  • meta is host data — array<string, mixed>|null — that the package stores and hands back but never reads.
  • With the database store, set recipients.key-type (bigint, uuid or ulid) to match your models’ keys before migrating.

The shipped jobs deliver to reachableAt, so a model recipient without an address needs your own job — see Custom delivery jobs. There the recipient resolves its model:

// In your own ProcessesCampaignRecipient job:
$recipient = $this->recipient;

$recipient->hasModel();        // true — it stands for a model
$recipient->isFor($user);      // stands for this model (keys compare as strings)
$recipient->meta;              // ['locale' => 'sk']

$user = $recipient->model();   // fresh lookup through the morph map; null when address-only or deleted
$user?->notify(new OfficeClosedNotice($this->campaign));

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.