Delivery channels
Each recipient is processed by the job in campaigns.process-recipient-job. Two ship with the package — both queued, both implementing Contracts\ProcessesCampaignRecipient:
- Jobs\SendCampaignEmail (default) — sends the campaign content as an HTML email.
- Jobs\SendCampaignNotification — delivers through Laravel’s notification system, so the same campaign can go out by email, SMS or push.
SendCampaignEmail sends the content exactly as stored — the same HTML body for every recipient, with no per-recipient templating — using the campaign subject and sender, addressed to the recipient’s name and address. A campaign without a sender keeps the mailer’s global mail.from address and name. Success marks the recipient processed; any exception is caught and recorded as a failed recipient with its message. A cancelled batch makes the job return without sending.
Laravel notifications
Switch the job, then point campaigns.notification at a CampaignNotification subclass and set the route channel:
// config/campaigns.php
'process-recipient-job' => \RoundlyConsulting\Campaigns\Jobs\SendCampaignNotification::class,
'notification' => \App\Notifications\ProductLaunchNotification::class,
'notification-channel' => 'mail',Your notification is constructed with the Campaign and the CampaignRecipient — both public readonly properties — so each channel method can render its own content:
namespace App\Notifications;
use Illuminate\Notifications\Messages\MailMessage;
use RoundlyConsulting\Campaigns\Notifications\CampaignNotification;
final class ProductLaunchNotification extends CampaignNotification
{
public function via(object $notifiable): array
{
return ['mail'];
}
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->subject($this->campaign->subject)
->greeting('Hello '.$this->recipient->name)
->line($this->campaign->content);
}
}The job routes an on-demand notifiable on campaigns.notification-channel (the DefaultChannel option) to the recipient’s reachableAt, then sends your notification. For SMS or push, set the channel to the one you have installed — vonage, fcm and so on — and resolve phone contacts with viaContactType(ContactType::Phone). If campaigns.notification is unset, every recipient fails with a CampaignException naming the missing config.
Need a transport that isn’t a Laravel notification? Write your own job — see Custom delivery jobs.
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 cryptoBy 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.