ttskch / monolog-mailgun
Monolog handler for Mailgun
Installs: 1 537
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.2
- guzzlehttp/psr7: ^1.4
- mailgun/mailgun-php: ^2.4
- monolog/monolog: ^2.0
- php-http/curl-client: ^1.7
Requires (Dev)
- phpunit/phpunit: ^6.0 || ^7.0 || ^8.0
README
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🙏