noneym/laravel10-cloudflare-mail

Cloudflare Email Service (REST API) transport for Laravel 10, 11 and 12 — PHP 8.2 & 8.3 compatible.

Maintainers

Package info

github.com/noneym/laravel10-cloudflare-mail

pkg:composer/noneym/laravel10-cloudflare-mail

Statistics

Installs: 24

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-init 2026-04-21 16:05 UTC

This package is auto-updated.

Last update: 2026-04-21 16:13:53 UTC


README

A Laravel mail transport for the Cloudflare Email Service REST API, compatible with Laravel 10, 11, and 12 and PHP 8.2 / 8.3.

Inspired by toitzi/laravel-cloudflare-mail, rewritten to drop the PHP 8.4 / Laravel 12-only requirement so it runs on older Laravel 10 codebases.

Requirements

Package Version
PHP ^8.2 (tested on 8.2 and 8.3)
Laravel ^10.0 || ^11.0 || ^12.0
Symfony Mailer ^6.2 || ^7.0 (ships with Laravel)

You also need:

  • A Cloudflare Account ID
  • A Cloudflare API token with the Email Sending permission
  • A domain onboarded to Cloudflare Email Service (DNS verified)

Installation

composer require noneym/laravel10-cloudflare-mail

The service provider is auto-discovered.

Configuration

.env

MAIL_MAILER=cloudflare

CLOUDFLARE_EMAIL_ACCOUNT_ID=your_cloudflare_account_id
CLOUDFLARE_EMAIL_API_TOKEN=your_api_token_with_email_sending_permission
# Optional override:
CLOUDFLARE_EMAIL_BASE_URL=https://api.cloudflare.com/client/v4

MAIL_FROM_ADDRESS=noreply@yourdomain.com
MAIL_FROM_NAME="Your App"

config/mail.php

Add a cloudflare mailer entry:

'default' => env('MAIL_MAILER', 'cloudflare'),

'mailers' => [

    // ... your other mailers

    'cloudflare' => [
        'transport'       => 'cloudflare',
        'account_id'      => env('CLOUDFLARE_EMAIL_ACCOUNT_ID'),
        'api_token'       => env('CLOUDFLARE_EMAIL_API_TOKEN'),
        'base_url'        => env('CLOUDFLARE_EMAIL_BASE_URL', 'https://api.cloudflare.com/client/v4'),
        'timeout'         => 30,
        'connect_timeout' => 10,
    ],

],

That's it — Laravel's Mail facade, Mailable classes, notifications, and queued mail all work as-is.

Usage

Quick send

use Illuminate\Support\Facades\Mail;

Mail::raw('Hello from Cloudflare!', function ($message) {
    $message->to('user@example.com')->subject('Welcome');
});

Mailable

Mail::to($user)->send(new \App\Mail\WelcomeMail($user));

Notifications

// in Notification class
public function via($notifiable)
{
    return ['mail'];
}

Nothing else changes — Laravel routes it through the cloudflare transport automatically.

What's supported

  • HTML and plain-text bodies
  • to, cc, bcc
  • Single from and single reply_to
  • Regular file attachments (base64-encoded)
  • Custom headers (except headers reserved by Cloudflare)

Cloudflare REST API limitations

These are Cloudflare limits, not package limits:

  • Only one from address per request
  • Only one reply_to address per request
  • Inline attachments are not supported and will throw a CloudflareTransportException
  • The from address must be on a domain that is verified in Cloudflare Email Service
  • Daily send quota applies (e.g. 1000/day on the free tier)

Error handling

Failures raise Noneym\LaravelCloudflareMail\Exceptions\CloudflareTransportException, which includes the HTTP status code and the Cloudflare error payload when available.

use Noneym\LaravelCloudflareMail\Exceptions\CloudflareTransportException;

try {
    Mail::to('user@example.com')->send(new WelcomeMail());
} catch (CloudflareTransportException $e) {
    report($e);
}

Testing the package itself

composer install
composer test

Security

Never commit your Cloudflare API token. Keep it in .env and rotate it via the Cloudflare dashboard if exposed.

Credits

License

MIT — see LICENSE.