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' => [ 'olivier@example.com' => "Olivier Laviale" ]
'to' => "Person name<person@example.com>, person2@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!
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::$mailer
property that returns a Mailer instance. - The
ICanBoogie\Core::mailer
method that sends a message using the mailer.
<?php
$app = ICanBoogie\boot();
$app->mailer; //instace of ICanBoogie\Mailer\Mailer;
$app->mail([
'to' => "example@example.com",
'from' => "me@example.com",
'subject' => "Testing",
'body' => "Hello world!"
], $options = []);
If sender
is defined in the mail()
options the following events are triggered:
- The
<class>:mail:before
event 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. - The
<class>:mail
event 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.
Where <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
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 make doc
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.