ttskch/monolog-mailgun

Monolog handler for Mailgun

1.0.5 2020-04-16 08:05 UTC

This package is auto-updated.

Last update: 2024-10-16 17:49:41 UTC


README

Build Status Latest Stable Version Total Downloads

Monolog handler for Mailgun using mailgun/mailgun-php.

Requirements

  • php:^7.2
  • monolog/monolog:^2.0

Installation

$ composer require ttskch/monolog-mailgun

Usage

$mg = \Mailgun\Mailgun::create('api_key');
$domain = 'mg.example.com';
$from = 'Alice <alice@example.com>';
$to = ['bob@foo.bar.com'];
$subject = '[Monolog] Error Report';

$handler = new \Ttskch\Monolog\Handler\MailgunHandler($mg, $domain, $from, $to, $subject);
$logger = new \Monolog\Logger('mailgun');
$logger->pushHandler($handler);
$logger->critical('Critical Error!');

Examples of framework integrations

Symfony4/5

# config/packages/mailgun.yaml
services:
    Mailgun\Mailgun:
        class: Mailgun\Mailgun
        factory: ['Mailgun\Mailgun', create]
        arguments: ['%env(MAILGUN_API_KEY)%']
# config/packages/prod/monolog.yaml
monolog:
    handlers:

        # ...

        email:
            type: fingers_crossed
            action_level: critical
            level: debug
            channels: ["!event"]
            handler: deduplicated
        deduplicated:
            type: deduplication # prevent multiply sending
            handler: mailgun
        mailgun:
            type: service
            id: Ttskch\Monolog\Handler\MailgunHandler

services:
    Ttskch\Monolog\Handler\MailgunHandler:
        arguments:
            - '@Mailgun\Mailgun'
            - mg.example.com # mailgun domain
            - Alice <alice@example.com> # from
            - [bob@foo.bar.com] # to
            - '[Monolog] Error Report' # subject
# .env
MAILGUN_API_KEY=api_key

Other

Feel free to send me a PR🙏