Download the PHP package andrewdyer/mailer without Composer
On this page you can find all versions of the php package andrewdyer/mailer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download andrewdyer/mailer
More information about andrewdyer/mailer
Files in andrewdyer/mailer
Package mailer
Short Description A framework-agnostic library for sending emails from Twig templates, with support for a swappable transport interface.
License MIT
Homepage https://github.com/andrewdyer/mailer
Informations about the package mailer
Mailer
A framework-agnostic library for sending emails from Twig templates, with support for a swappable transport interface.
Introduction
This library renders Twig templates to HTML and dispatches them through an extensible, swappable transport interface, with a Symfony Mailer transport included out of the box. Custom transports can be introduced by implementing a simple contract, making it straightforward to adapt the delivery pipeline to different mailing backends or infrastructure requirements.
Prerequisites
- PHP: Version 8.3 or higher is required.
- Composer: Dependency management tool for PHP.
- Twig: Version ^3.27 is required.
Installation
Getting Started
1. Create a Twig template
Create an HTML template in the application's templates directory:
2. Create a mailable
Extend Mailable and implement envelope() to configure the routing and content() to define the template and data:
3. Set up the mailer
Instantiate Mailer with a Twig\Environment, a transport, and an optional default from address:
Usage
Sending a mailable
Dispatch any Mailable instance via the send() method:
Attaching files
Implement AttachableInterface on the mailable and return an array of absolute file paths:
Envelope
A value object defining the routing and metadata for a message. Only to and subject are required — all other properties are optional and can be passed in any order using named arguments:
Setting a from address
The defaultFrom address set on Mailer is used when from is omitted. Set it explicitly on the Envelope to override it for a specific mailable:
Adding CC and BCC recipients
Pass arrays of Address instances to cc and bcc on the Envelope:
Setting priority
Pass a Priority enum value to priority on the Envelope:
Transports
Symfony Mailer
A transport backed by Symfony Mailer, supporting SMTP and a wide range of third-party providers via DSN strings.
Then instantiate the transport with a DSN string:
Common DSN formats:
Custom transports
Any class implementing TransportInterface can be used as a transport, accepting a PreparedMessage and dispatching it:
License
Licensed under the MIT licence and is free for private or commercial projects.