Download the PHP package mydnic/laravel-subscribers without Composer

On this page you can find all versions of the php package mydnic/laravel-subscribers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-subscribers

Kanpen

Latest Version on Packagist PHP Laravel Filament

A lightweight newsletter subscriber management package for Laravel. Handle subscriptions, send campaigns, track opens and clicks — all without a third-party service.

Heads-up: This package is designed for small to medium audiences (think side-projects, indie apps, internal tools). It sends mail through whatever driver is configured in your config/mail.php and has no bounce handling, no complaint webhooks, and no deliverability tooling. If you're sending to tens of thousands of subscribers or need professional deliverability guarantees, use a dedicated email service provider instead. Sendboo is a great option with full campaign management, AI features, and solid deliverability.


Features


Requirements


Table of Contents


Installation

Install via Composer:

The service provider is auto-discovered. Next, publish and run the migrations:

This creates three tables: subscribers, campaigns, and campaign_deliveries.


Configuration

Publish the config file:

This creates config/kanpen.php:


Subscriber Management

Web Form

Add a form anywhere in your Blade views:

On success the user is redirected to the route defined in redirect_url with a subscribed session flash message.

API Endpoint

A JSON endpoint is also available:

Response 201 Created:

Duplicate emails return a 422 Unprocessable Entity with a validation error.

Throttling

Both subscribe endpoints are public and send mail, so they are rate limited out of the box by a named limiter, kanpen-subscribe. Two caps apply at once:

Cap Default What it stops
per IP 10 per minute one client hammering the endpoint
per email address 3 per hour a pool of IPs burying a single mailbox

Over the limit, the endpoints return 429 Too Many Requests. Adjust the numbers in the throttle config key, or set throttle.enabled to false if you prefer to apply your own middleware.

Email addresses are lowercased and trimmed before they are counted, and only their hash is kept in the limiter cache. A request that carries no address, or something other than a string, is capped per IP only: it never reaches a mailbox, so it stops at validation with a 422 instead of being counted against a shared bucket.

Programmatic Subscription

Add the HasNewsletterSubscription trait to any Eloquent model that has an email attribute:

Then call the trait methods:

If verify is enabled in config, subscribe() automatically sends the verification email.

Email Verification

Set KANPEN_VERIFY=true in your .env (or set 'verify' => true in config) to enable double opt-in. When enabled:

You can customise every line of the verification email in the mail.verify config key.

The verification route is GET /kanpen/verify/{id}/{hash} — this is handled automatically.

The link is a temporary signed URL and the route carries Laravel's signed middleware, so the signature is checked on arrival. A link that was not generated by the verification email is rejected with a 403, and so is one past verification_expiration. The {id} and {hash} segments are not a credential on their own: anyone who knows an address can compute them, which is why the signature is what actually proves the click came from the subscriber's mailbox.

Unsubscribing

Every subscriber gets a unique random unsubscribe_token generated automatically on creation. Use it to build a safe unsubscribe link — the subscriber's email address is never exposed in the URL:

This generates a URL like /kanpen/unsubscribe/Xk9mP... (64-char opaque token).

Unsubscribing takes two steps:

Method Route What it does
GET /kanpen/unsubscribe/{token} shows a confirmation page with a single button
DELETE /kanpen/unsubscribe/{token} soft-deletes the subscriber and shows the "unsubscribed" page

The GET never deletes anything. Mail clients and corporate link scanners (Outlook Safe Links, antivirus proxies) fetch every link in a message before the recipient sees it, so a one-click GET unsubscribe silently removes people who never clicked. Both pages are publishable and customisable — see Publishing Assets.

Neither route reveals whether the token exists, so the URL cannot be used to probe for addresses.

The token is also injected automatically into all campaign emails via the default base.blade.php layout, so you don't need to add it manually to campaigns.

Note: For subscribers created before this version (without a token), getUnsubscribeUrl() generates and persists a token on the fly. The backfill migration handles bulk assignment for existing rows.

Using the data layer without the package routes

If you'd rather register your own routes, turn the package ones off and point each link at yours:

The models, campaigns, jobs, commands and events keep working. The HTTP layer is skipped, but the links the package puts in an email are not: every one of them resolves a named route, so turning web off means you have to say which route takes its place.

Config key Used by Expected parameters
unsubscribe_name getUnsubscribeUrl() and the campaign footer {token}
<unsubscribe_name>.destroy the confirm form on the unsubscribe page {token}, DELETE
verify_name the verification email, as a signed URL {id}, {hash}
tracking_open_name the open pixel {token}
tracking_click_name the click proxy {token}, ?url=

You only need the routes for the features you run: verify_name is read when verify is on, and the two tracking names when tracking.enabled is on. Leave a name pointing at a route that does not exist with its feature enabled and the send throws RouteNotFoundException.

Pointing a name at your own route is enough, and the package controllers are not tied to the package routes:


Campaigns

Creating a Campaign

Use the Campaign model directly:

Campaigns are created in draft status and are not sent until you explicitly trigger a send.

Sending a Campaign

Inject or resolve the SendCampaignAction and call execute():

This dispatches a queued job that:

  1. Sets the campaign status to sending
  2. Chunks through all (verified) subscribers
  3. Creates a CampaignDelivery record with a unique tracking token per subscriber
  4. Dispatches an individual queued job per subscriber that sends the email
  5. Sets the status to sent once all jobs are dispatched

Make sure you have a queue worker running:

Scheduling a Campaign

Set scheduled_at on a campaign to send it at a specific time in the future:

The campaign stays in draft status and is sent automatically when its scheduled_at time passes.

How It Works

The package registers the kanpen:dispatch-scheduled Artisan command on your application scheduler and runs it every minute:

This command queries for all draft campaigns whose scheduled_at is in the past and calls SendCampaignAction::execute() on each of them. Internally this dispatches SendCampaignJob to your configured queue — the same path as an immediate send.

Important: Your scheduler must be running. Add this to your server's cron if you haven't already:

Opting Out of Auto-Registration

If you prefer to schedule the command yourself (e.g. less frequently, or with a specific environment condition), set schedule to false in config and add the command manually in your Console/Kernel.php (Laravel 10) or bootstrap/app.php (Laravel 11+):


Custom Blade Views

By default campaigns are rendered using the package's built-in email layout. You can point a campaign to any Blade view in your application:

Your view receives these variables:

Variable Type Description
$campaign Campaign The campaign model
$send CampaignDelivery The per-subscriber send record
$subscriber Subscriber The subscriber receiving this email

Example view:

Tracking (open pixel and link rewriting) is applied automatically to the rendered HTML regardless of which view is used.

Campaign API

A full REST API for managing campaigns is available under /kanpen-api/campaigns. The middleware protecting these routes defaults to ['api'] and is configurable via campaigns.middleware in config.

Method Endpoint Description
GET /kanpen-api/campaigns List all campaigns (paginated)
POST /kanpen-api/campaigns Create a new campaign
GET /kanpen-api/campaigns/{id} Get campaign details + stats
PUT /kanpen-api/campaigns/{id} Update a draft campaign
DELETE /kanpen-api/campaigns/{id} Soft-delete a campaign
POST /kanpen-api/campaigns/{id}/send Dispatch the send job
POST /kanpen-api/campaigns/{id}/test Send a test copy to one address

Create a campaign:

Get campaign stats:

Send a test email:

The email is sent immediately (not queued) as an exact copy of what subscribers would receive — same subject, same content, same tracking links (though the token won't exist in the database so opens/clicks won't be recorded). Does not create any CampaignDelivery records or alter the campaign's status or counts. Works for campaigns in any status — useful for previewing already-sent campaigns too.

To add authentication to campaign routes, update the middleware in config:


Tracking

How It Works

When a campaign is sent, the package automatically processes every email's HTML before delivery:

  1. Open tracking — a 1×1 transparent GIF pixel is injected just before </body>:

    When a mail client loads the pixel, opened_at is set and open_count is incremented on the CampaignDelivery record.

  2. Click tracking — every <a href="..."> in the email is rewritten to go through a redirect proxy:

    When a subscriber clicks, the original URL is decoded, clicked_at is set, and the click is appended to click_log before the redirect.

Both tracking routes are public and do not require authentication. mailto: and #anchor links are left untouched.

Disabling Tracking

You can disable tracking globally or individually:

Restricting Click Tracking to Specific Domains

To prevent the click proxy from redirecting to arbitrary domains, set an allowlist:

Clicks to domains not on the list return a 403 response.

Tracking Events

Listen to tracking events in your EventServiceProvider:

Both events carry the CampaignDelivery model (which has the campaign, subscriber, and all tracking timestamps).


User Sync

You can automatically keep your application's users in sync with the subscribers table.

HasNewsletterSubscription Trait

Add the HasNewsletterSubscription trait to your User model and implement the two required methods.

How it works:

Important: Use updateQuietly() inside onUnsubscribed() to avoid triggering the saved event and causing a sync loop.

Manual sync trigger:

You can also call syncSubscriberRecord() directly:

Artisan Sync Command

To sync your existing users in bulk (e.g. after adding the trait to an app that already has users), use the kanpen:sync command:

This calls syncSubscriberRecord() on every record, which in turn calls your shouldBeSubscribed() implementation. Records that return true are subscribed (or restored if previously unsubscribed), records that return false are soft-deleted from the subscribers table.


Events Reference

All events live in the Mydnic\Kanpen\Events namespace.

Event Fired When Properties
SubscriberCreated A new subscriber is saved $subscriber
SubscriberDeleted A subscriber is deleted $subscriber
SubscriberVerified A subscriber verifies their email $subscriber
CampaignDeliverying A campaign's send job starts $campaign
CampaignSent All subscriber jobs are dispatched $campaign
EmailOpened A tracking pixel is loaded $send
EmailLinkClicked A tracked link is clicked $send, $url

Publishing Assets

Views

Publish and customise the email layout and unsubscribe page:

Files are copied to resources/views/vendor/kanpen/:

If you override unsubscribe.blade.php, keep the form posting to route('kanpen.unsubscribe.destroy', ['token' => $token]) with @csrf and @method('DELETE') — that post is what actually unsubscribes.

Laravel's view resolution picks up your published files automatically — no config change needed.

Filament Integration

A first-party Filament plugin is available at mydnic/kanpen-filament-plugin.

It adds a full admin UI on top of Kanpen:

See the plugin README for full installation and usage instructions.


Upgrading

From v1.x to v2.x

v2 is a breaking release. The following changes require attention:

PHP and Laravel requirements

Model namespace

The Subscriber model has moved from Mydnic\Subscribers\Subscriber to Mydnic\Kanpen\Models\Subscriber.

The old class still exists as a deprecated alias, so existing code continues to work, but you should update your imports:

Migrations

Publish and run the new migrations to create the campaigns and campaign_deliveries tables:

Events

The three subscriber events (SubscriberCreated, SubscriberDeleted, SubscriberVerified) no longer implement ShouldBroadcast. If you were broadcasting these events, re-implement broadcasting in your own listeners.


License

The MIT License (MIT). See LICENSE for details.


All versions of laravel-subscribers with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
laravel/framework Version >=10.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mydnic/laravel-subscribers contains the following files

Loading the files please wait ...