go-redrock / swiftmailer
Swiftmailer, free feature-rich PHP mailer -- maintained by Redrock Software Corporation with Symfony Mailer features back-ported for legacy and enterprise applications
Requires
- php: >=8.3
- ext-iconv: *
- ext-intl: *
- ext-mbstring: *
- ext-openssl: *
- async-aws/ses: ^1.8
- egulias/email-validator: ^2.0|^3.1|^4.0.2
- google/apiclient: ^2.16
- guzzlehttp/guzzle: ^7.0
- league/oauth2-client: ^2.7
- league/oauth2-google: ^4.0
- microsoft/microsoft-graph: ^2.10
- nyholm/dsn: 2.*
- phpseclib/phpseclib: ^3.0.52
- stevenmaguire/oauth2-microsoft: ^2.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.57
- infection/infection: ^0.29
- mockery/mockery: ^1.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^9.6.33
- rector/rector: ^2.0
- roave/security-advisories: dev-master
- symfony/phpunit-bridge: ^4.4|^5.4
- tijsverkoyen/css-to-inline-styles: ^2.4
Suggests
- ext-intl: Needed to support internationalized email addresses
- tijsverkoyen/css-to-inline-styles: For automatic CSS inlining in HTML emails (Swift_Plugins_CssInlinerPlugin)
This package is auto-updated.
Last update: 2026-08-10 20:37:55 UTC
README
A component-based PHP mailing library, maintained by Redrock Software Corporation. This fork integrates features from Symfony Mailer back into SwiftMailer for legacy and enterprise applications that cannot migrate to Symfony Mailer.
About This Fork
The original SwiftMailer was abandoned by its creators in November 2021. Redrock Software Corporation picked up maintenance in 2022 to serve the many legacy and enterprise PHP applications that depend on SwiftMailer and cannot practically migrate to Symfony Mailer.
What We've Done
Since taking over, Redrock has shipped a major modernization of SwiftMailer (v6.4.0) that back-ports the most valuable Symfony Mailer capabilities while preserving full backward compatibility:
- 21 HTTP API transports -- SendGrid, Mailgun, Postmark, Brevo, Amazon SES, Azure, Gmail API, Microsoft Graph, Resend, Scaleway, InfoBip, MailPace, Mandrill, MailerSend, Mailjet, AhaSend, Mailomat, Mailtrap, Postal, Sweego, and more
- DSN transport factory -- create any transport from a connection string, with
failover(),roundrobin(), andretry()wrappers - Webhook system -- process inbound delivery/bounce/engagement webhooks from 14 providers with signature verification
- New events --
SentMessageEventandFailedMessageEventfor post-send tracking - New plugins --
AllowlistPlugin(dev/staging safety),CssInlinerPlugin(auto CSS inlining),SentMessagePlugin(post-send inspection),ReadReceiptPlugin(MDN read receipts + tracking pixel) - DKIM enhancements -- Ed25519-SHA256 signing, header oversigning
- SMTP improvements -- Auto TLS, Smart SMTPUTF8, explicit envelope control via
Swift_Envelope - RetryTransport -- automatic retries with exponential backoff for any transport
- Security hardening --
#[SensitiveParameter]on API keys, Guzzle exception sanitization, serialization blocking - Modern tooling -- PHP 8.3+ baseline, PHPStan static analysis, CI pipeline with GitHub Actions, Infection mutation testing, PHP-CS-Fixer
- CLI test tool --
bin/swiftmailer-testfor validating transport configuration from the command line
The Future of SwiftMailer
SwiftMailer is not dead -- it's actively maintained and developed. Our roadmap includes:
- Continued Symfony Mailer parity -- closing the remaining feature gaps (see docs/SYMFONY_MAILER_PARITY.md)
- Additional API transports -- expanding provider coverage as new services emerge
- PHP version support -- staying current with the latest PHP releases
- Community contributions -- we welcome pull requests, bug reports, and feature requests
If your application uses SwiftMailer, you don't have to migrate. Upgrade to this fork and get modern features with zero code changes to your existing mail code.
Requirements
- PHP 8.3+
- Extensions:
iconv,mbstring,intl,openssl
Installation
composer require go-redrock/swiftmailer
Quick Start
SMTP
$transport = new Swift_SmtpTransport('smtp.example.com', 587, 'tls'); $transport->setUsername('user@example.com'); $transport->setPassword('secret'); $mailer = new Swift_Mailer($transport); $message = (new Swift_Message('Hello')) ->setFrom(['sender@example.com' => 'Sender']) ->setTo(['recipient@example.com']) ->setBody('<h1>Hello!</h1>', 'text/html'); $mailer->send($message);
API Transport (SendGrid)
$transport = new Swift_Transport_Api_SendgridTransport('your-sendgrid-api-key'); $mailer = new Swift_Mailer($transport); $mailer->send($message);
DSN Factory
$factory = new Swift_Transport_DsnTransportFactory(); // Single transport $transport = $factory->fromDsnString('sendgrid://API_KEY@default'); // Failover between two providers $transport = $factory->fromDsnString('failover(sendgrid://KEY@default postmark://KEY@default)'); // Round-robin load balancing $transport = $factory->fromDsnString('roundrobin(sendgrid://KEY@default postmark://KEY@default)'); // Retry with exponential backoff $transport = $factory->fromDsnString('retry(sendgrid://KEY@default)'); $mailer = new Swift_Mailer($transport);
Features
21 HTTP API Transports
SendGrid, Mailgun, Postmark, Brevo, Amazon SES (API + HTTP), Azure Communication Services, Google Gmail API, Microsoft Graph, Resend, Scaleway, InfoBip, MailPace, MailChimp/Mandrill, MailerSend, Mailjet, AhaSend, Mailomat, Mailtrap, Postal, Sweego.
See doc/api-transports.md for constructor arguments, authentication, and examples.
DSN Transport Factory
Create any transport from a connection string. Supports failover(), roundrobin(), and retry() wrappers for redundancy, load balancing, and automatic retries with exponential backoff.
See doc/dsn.md for the full scheme reference.
RetryTransport
Wrap any transport with automatic retry logic featuring exponential backoff:
$inner = new Swift_Transport_Api_SendgridTransport('SG.your-key'); $transport = new Swift_RetryTransport($inner, maxRetries: 3, baseDelay: 1000); // Or via DSN $transport = $factory->fromDsnString('retry(sendgrid://KEY@default)');
Tags and Metadata
Attach tags and metadata to messages via headers. API transports automatically map them to each provider's native format.
$message->getHeaders()->addTextHeader('X-Mailer-Tag', 'welcome-email'); $message->getHeaders()->addTextHeader('X-Mailer-Metadata-user_id', '12345');
See doc/api-transports.md for provider-specific mapping details.
Webhook System
Process inbound webhooks from 14 email providers to track deliveries, bounces, opens, clicks, and complaints. Supported providers: SendGrid, Mailgun, Postmark, Amazon SES, Brevo, Resend, MailerSend, Mailjet, Mandrill, AhaSend, Mailomat, Mailtrap, Sweego, MailPace.
See doc/webhooks.md for setup and provider-specific examples.
New Plugins
- AllowlistPlugin -- restrict delivery to allowed recipients/domains with descriptive rejection reasons (dev/staging safety)
- CssInlinerPlugin -- automatically inline CSS in HTML emails before sending
- SentMessagePlugin -- capture
Swift_SentMessageobjects for post-send inspection - ReadReceiptPlugin -- toggleable MDN read receipts and/or tracking-pixel injection
See doc/plugins.md for configuration and usage.
New Events
- SentMessageEvent -- fired after successful send, carries
Swift_SentMessagewith provider message ID - FailedMessageEvent -- fired on send failure, carries exception and failed recipient list
See doc/events.md for the complete event lifecycle.
DKIM Signing
Enhanced DKIM signer with support for:
- Ed25519-SHA256 algorithm (
ed25519-sha256) in addition to RSA-SHA256 - Oversigning of From, Subject, and other headers to prevent header injection
- Modernized API with fluent configuration
$signer = new Swift_Signers_DKIMSigner($privateKey, 'example.com', 'selector'); $signer->setHashAlgorithm('ed25519-sha256'); // Oversigning of From/To/Subject/Date/Cc/Reply-To/Message-ID is on by default $message->attachSigner($signer);
Swift_Envelope
Explicit SMTP envelope control, separating the SMTP envelope sender/recipients from the message headers:
$envelope = new Swift_Envelope('bounce-handler@example.com', ['actual-recipient@example.com']); $mailer->send($message, $failedRecipients, $envelope);
SMTP Enhancements
- Auto TLS -- STARTTLS negotiation mode alongside traditional
ssl/tls - Smart SMTPUTF8 --
AutoAddressEncoderdetects SMTPUTF8 server capability and switches encoding automatically - DSN parameters --
verify_peer,peer_fingerprint,source_ip,smtputf8via DSN query string
Security Hardening
#[SensitiveParameter]on all API key constructor parameters (PHP 8.2+)- Guzzle exception chain sanitized to prevent API key leakage in stack traces
- Serialization blocked on transport objects (
__sleep/__wakeupthrow)
CLI Testing Tool
The bin/swiftmailer-test command-line tool validates your transport configuration:
./bin/swiftmailer-test 'sendgrid://SG.your-key@default'
CI & Quality
- GitHub Actions CI pipeline with a PHP 8.3--8.5 test matrix
- GitLab CI pipeline with unit tests (PHP 8.3/8.5), Mailpit smoke tests, and Infection mutation testing
- PHPStan level 5 static analysis
- PHP-CS-Fixer code style enforcement
Documentation
The complete documentation lives in doc/ -- no external docs site required.
| Document | Description |
|---|---|
| doc/introduction.md | Requirements, installation, first email |
| doc/messages.md | Building messages: bodies, attachments, embedded files, MIME parts |
| doc/headers.md | Header types and the header set API |
| doc/sending.md | Transports, send(), envelopes, spooling, retries, message limits |
| doc/api-transports.md | All 21 API transports -- constructors, auth, examples |
| doc/microsoft-graph.md | Microsoft Graph: auth modes, large attachments, calendar invites |
| doc/dsn.md | DSN syntax reference and all supported schemes |
| doc/cli.md | The swiftmailer-test CLI tool |
| doc/events.md | Event lifecycle, listener interfaces, dispatch points |
| doc/webhooks.md | Webhook processing for delivery and engagement events |
| doc/plugins.md | All 14 bundled plugins and writing your own |
| doc/signers.md | DKIM, DomainKeys, and S/MIME signing |
| doc/security.md | Security hardening: defaults and opt-in protections |
| doc/architecture.md | Codebase internals for contributors |
| doc/upgrading.md | Migration guide from stock SwiftMailer 6.x |
| CONTRIBUTING.md | Dev setup, tests, style, static analysis, CI |
Sponsors
License
MIT License. See LICENSE for details.