noneym / laravel10-cloudflare-mail
Cloudflare Email Service (REST API) transport for Laravel 10, 11 and 12 — PHP 8.2 & 8.3 compatible.
Package info
github.com/noneym/laravel10-cloudflare-mail
pkg:composer/noneym/laravel10-cloudflare-mail
Requires
- php: ^8.2
- ext-json: *
- illuminate/http: ^10.0 || ^11.0 || ^12.0
- illuminate/mail: ^10.0 || ^11.0 || ^12.0
- illuminate/support: ^10.0 || ^11.0 || ^12.0
- symfony/mailer: ^6.2 || ^7.0
- symfony/mime: ^6.2 || ^7.0
Requires (Dev)
- orchestra/testbench: ^8.0 || ^9.0 || ^10.0
- phpunit/phpunit: ^10.0 || ^11.0
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
fromand singlereply_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
fromaddress per request - Only one
reply_toaddress per request - Inline attachments are not supported and will throw a
CloudflareTransportException - The
fromaddress 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
- Original inspiration:
toitzi/laravel-cloudflare-mailby Tobias Oitzinger - Cloudflare Email Service: https://developers.cloudflare.com/email-service/
License
MIT — see LICENSE.