Mailer is a library for PHP that is designed to handle emails generation and sending.
This package was inspired by the following softwares or articles:
<?php use ICanBoogie\Mailer\Message; $message = new Message([ 'from' => [ 'email@example.com' => "Olivier Laviale" ] 'to' => "Person name<firstname.lastname@example.org>, email@example.com", 'subject' => "Testing message", 'body' => "Hello world!" ]); echo $message->header; // Content-Type: text/plain; charset=UTF-8\r\nFrom: Olivier Laviale <olivier@ex… echo $message; // Hello world!
Sending a message
Messages are sent by a deliverer through a Mailer instance.
The following example demonstrates how a mailer can be used to send emails using the default mail deliverer:
<?php use ICanBoogie\Mailer\Mailer; $mailer = new Mailer; $rc = $mailer($message);
The following example demonstrates how a mailer can be used to send emails using the file deliverer:
<?php use ICanBoogie\Mailer\Mailer; use ICanBoogie\Mailer\FileDeliverer; $mailer = new Mailer(new FileDeliverer('/path/to/my/file'); $rc = $mailer($message);
The package supports the auto-config feature of the framework ICanBoogie and provides the following features:
- The lazy getter for the
ICanBoogie\Core::$mailerproperty that returns a Mailer instance.
ICanBoogie\Core::mailermethod that sends a message using the mailer.
<?php $app = ICanBoogie\boot(); $app->mailer; //instace of ICanBoogie\Mailer\Mailer; $app->mail([ 'to' => "firstname.lastname@example.org", 'from' => "email@example.com", 'subject' => "Testing", 'body' => "Hello world!" ], $options = );
Before and after the message is sent
sender is defined in the
mail() options the following events are triggered:
<class>:mail:beforeevent of class BeforeMailEvent is fired before the message is sent by the mailer. Third parties may use this event to alter the message or the mailer that will be used to send it.
<class>:mailevent of class MailEvent is fired after the message was sent by the mailer. Third parties may use this event to alter the result returned by the mailer.
<class> is the class of the sender.
The package requires PHP 5.4 or later.
The recommended way to install this package is through Composer:
$ composer require icanboogie/mailer
Cloning the repository
The package is available on GitHub, its repository can be cloned with the following command line:
$ git clone https://github.com/ICanBoogie/Mailer.git
The documentation can be generated for the package and its dependencies with the
command. The documentation is generated in the
docs directory. ApiGen is
required. The directory can later be cleaned with the
make clean command.
The test suite is ran with the
make test command. Composer is
automatically installed as well as all the dependencies required to run the suite.
The directory can later be cleaned with the
make clean command.
The package is continuously tested by Travis CI.
This package is licensed under the New BSD License - See the LICENSE file for details.