PHPackages                             kadirgulec/newsletter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. kadirgulec/newsletter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

kadirgulec/newsletter
=====================

A robust newsletter package for Laravel

v1.1.0(6mo ago)157MITPHP

Since Dec 23Pushed 1mo agoCompare

[ Source](https://github.com/kadirgulec/laravel-newsletter)[ Packagist](https://packagist.org/packages/kadirgulec/newsletter)[ RSS](/packages/kadirgulec-newsletter/feed)WikiDiscussions main Synced today

READMEChangelog (4)Dependencies (1)Versions (6)Used By (0)

Laravel Newsletter Package
==========================

[](#laravel-newsletter-package)

A lightweight, database-driven newsletter system for Laravel. It handles subscriptions, unsubscriptions via secure signed URLs, and sends RFC-compliant emails to ensure high deliverability (Gmail/Outlook friendly).

Features
--------

[](#features)

- 📦 **Database Storage:** Saves subscribers to a local `newsletter_subscribers` table.
- 🔒 **Signed Unsubscribe Links:** Prevents users from unsubscribing others by protecting the route with a cryptographic signature.
- 📧 **RFC Compliance:** Automatically adds `List-Unsubscribe` headers to email responses.
- 🎨 **Ready-to-use Views:** Includes a standard email layout and unsubscribe success page.
- ⚡ **Laravel 10, 11 &amp; 12 Support.**

---

Installation
------------

[](#installation)

### Installing via Composer

[](#installing-via-composer)

```
    composer require kadirgulec/newsletter
```

### Post-Installation

[](#post-installation)

After installing, run the migrations to create the subscribers table:

```
    php artisan migrate
```

---

Usage
-----

[](#usage)

### 1. The Subscription Form

[](#1-the-subscription-form)

You can place this HTML form anywhere in your application (footer, sidebar, popup, etc.).

```

    @if(session('success'))
        {{ session('success') }}
    @endif

    @error('email')
        {{ $message }}
    @enderror

        @csrf

        Subscribe

```

### 2. Sending a Newsletter

[](#2-sending-a-newsletter)

You can send a newsletter from any Controller, Artisan Command, or Job.

```
    use Illuminate\Support\Facades\Mail;
    use KadirGulec\Newsletter\Models\Subscriber;
    use KadirGulec\Newsletter\Mail\NewsletterMail;

    // 1. Fetch only active subscribers
    $subscribers = Subscriber::active()->get();

    // 2. Iterate and send
    foreach ($subscribers as $subscriber) {
        Mail::to($subscriber->email)->send(
            new NewsletterMail(
                $subscriber,                                // 1. Subscriber Model
                "Weekly Digest: New Updates",               // 2. Email Subject
                "Hello!Here is the news..." // 3. Email Content (HTML)
            )
        );
    }

```

> **Tip:** For large lists, it is highly recommended to queue these emails using Laravel Jobs to prevent your page from timing out.

### 3. Unsubscribing

[](#3-unsubscribing)

This process is automated and prefetch-safe.

1. Every email sent via `NewsletterMail` includes a **Footer Link** and the **`List-Unsubscribe`** + **`List-Unsubscribe-Post: List-Unsubscribe=One-Click`** headers (RFC 8058).
2. The signed URL (`/newsletter/unsubscribe/{id}?signature=...`) responds to both:
    - **`GET`** — renders a confirmation page with a button. Mailbox link-scanners and antivirus prefetchers that hit the URL do **not** unsubscribe the user.
    - **`POST`** — performs the unsubscribe. Used by the confirmation form and by mailbox providers (Gmail, Outlook, …) when the user clicks their built-in "Unsubscribe" UI.
3. On successful unsubscribe, `unsubscribed_at` is set and the user sees the `unsubscribe-success` view.

If the same email later resubscribes through the form, `unsubscribed_at` is cleared and `subscribed_at` is refreshed.

---

Database Structure
------------------

[](#database-structure)

The package creates a table named `newsletter_subscribers`.

ColumnTypeDescription`id`BigIntPrimary Key`email`StringUnique email address`subscribed_at`TimestampNullable. Set when the user subscribes; cleared/unused implies they were never confirmed`unsubscribed_at`TimestampNullable. Set when the user unsubscribes; `null` means still active`unsubscribe_reason`TextNullable. Optional free-text reason captured at unsubscribe time`created_at`TimestampRow insert date`updated_at`TimestampRow update date`deleted_at`TimestampNullable. Reserved for soft deletesA subscriber is considered active when `subscribed_at IS NOT NULL` and `unsubscribed_at IS NULL`. Use the `Subscriber::active()` scope rather than checking the columns directly.

The package also creates a table named `newsletter_campaigns`.

ColumnTypeDescription`id`BigIntPrimary Key`subject`StringThe email subject`content`LongTextThe HTML content of the email`status`String`draft` or `sent``sent_at`TimestampNullable. Date when the campaign was sent---

Customization
-------------

[](#customization)

### Publishing Views

[](#publishing-views)

You can publish the email layout and the "Unsubscribe Success" page to your main `resources/views` folder to customize them.

```
    php artisan vendor:publish --tag=newsletter-views
```

This will generate:

1. `resources/views/vendor/newsletter/email/standard.blade.php` (The Email Layout)
2. `resources/views/vendor/newsletter/confirm-unsubscribe.blade.php` (The "Confirm unsubscribe" page)
3. `resources/views/vendor/newsletter/unsubscribe-success.blade.php` (The "You have unsubscribed" page)

### Extending the Model

[](#extending-the-model)

If you need to add relationships (e.g., linking a subscriber to a `User`), you can extend the model or use the provided one:

```
    use KadirGulec\Newsletter\Models\Subscriber;

    // Check if a specific email is currently subscribed
    $isSubscribed = Subscriber::active()->where('email', 'john@doe.com')->exists();
```

---

Troubleshooting
---------------

[](#troubleshooting)

**Error: Route \[newsletter.subscribe\] not defined.**

- Ensure the service provider is loaded. Run `php artisan route:list | grep newsletter` to check if routes are registered.
- Try running `php artisan optimize:clear`.

**Error: 403 Invalid Signature on Unsubscribe.**

- This happens if the URL is modified. Ensure your `APP_URL` in `.env` is set correctly (e.g., `http://localhost:8000` or `https://yourdomain.com`). Signed routes use the `APP_URL` to generate the signature.

---

Testing
-------

[](#testing)

The package includes a comprehensive test suite using PHPUnit and Orchestra Testbench.

### Running Tests

[](#running-tests)

1. Install development dependencies:

```
    composer install
```

2. Run the tests:

```
    vendor/bin/phpunit
```

The tests cover:

- **Subscriber Model:** Active/Inactive scoping.
- **Newsletter Controller:** Subscription process and welcome email delivery.
- **Unsubscription:** Secure signed URL validation and status updates.
- **Campaigns:** Correct batch queueing to active subscribers only.

---

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance80

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

193d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/122262662?v=4)[Kadir Gülec](/maintainers/kadirgulec)[@kadirgulec](https://github.com/kadirgulec)

---

Top Contributors

[![kadirgulec](https://avatars.githubusercontent.com/u/122262662?v=4)](https://github.com/kadirgulec "kadirgulec (14 commits)")

### Embed Badge

![Health badge](/badges/kadirgulec-newsletter/health.svg)

```
[![Health](https://phpackages.com/badges/kadirgulec-newsletter/health.svg)](https://phpackages.com/packages/kadirgulec-newsletter)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M10](/packages/renatomarinho-laravel-page-speed)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M282](/packages/illuminate-pipeline)[illuminate/redis

The Illuminate Redis package.

8314.6M377](/packages/illuminate-redis)[illuminate/cookie

The Illuminate Cookie package.

244.6M137](/packages/illuminate-cookie)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
