Mailgun handler is a Monolog handler that email log entries using Mailgun API.
Mailgun handler requires PHP 7.1.3 or higher, Monolog 1.X or higher and Mailgun API 2.8 or higher.
The easiest way to install Mailgun handler is via composer typing the following command:
$ composer require fluchi/mailgun-handler
On your project's root, create a file called .env, if there is any, and added the following content:
# /.env
MAILGUN_API_KEY="your mailgun API key"
MAILGUN_DOMAIN="your mailgun domain"
MAILGUN_FROM="default from"
MAILGUN_TO="default to"
MAILGUN_FROM and MAILGUN_TO are optional.
Default level to email is Logger::WARNING. You can change as shown below.
After installation, Mailgun handler will be available over MailgunHandler
namespace.
use Monolog\Logger;
use MailgunHandler\MailgunHandler;
require __DIR__ . '/vendor/autoload.php';
$logger = new Logger('foobar-channel');
// email based on .env config file
$logger->pushHandler(new MailgunHandler('email subject'));
// email WARNING level
$logger->pushHandler(new MailgunHandler('email subject', null, null, Logger::WARNING));
// you can change from and to on parameters 2 and 3, respectivelly
$logger->pushHandler(new MailgunHandler('email subject', '[email protected]', '[email protected]'));
This library is licensed under the MIT license. See the LICENSE file for details.