https://github.com/ttskch/monolog-mailgun
Monolog handler for Mailgun which can be integrated with Symfony 4/5
https://github.com/ttskch/monolog-mailgun
mailgun monolog
Last synced: 10 months ago
JSON representation
Monolog handler for Mailgun which can be integrated with Symfony 4/5
- Host: GitHub
- URL: https://github.com/ttskch/monolog-mailgun
- Owner: ttskch
- License: mit
- Created: 2018-03-18T11:16:49.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-04-16T08:06:14.000Z (almost 6 years ago)
- Last Synced: 2025-02-08T12:25:50.079Z (about 1 year ago)
- Topics: mailgun, monolog
- Language: PHP
- Homepage:
- Size: 14.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# monolog-mailgun
[](https://travis-ci.org/ttskch/monolog-mailgun)
[](https://packagist.org/packages/ttskch/monolog-mailgun)
[](https://packagist.org/packages/ttskch/monolog-mailgun)
Monolog handler for [Mailgun](https://www.mailgun.com/) using [mailgun/mailgun-php](https://github.com/mailgun/mailgun-php).
## Requirements
* php:^7.2
* monolog/monolog:^2.0
## Installation
```bash
$ composer require ttskch/monolog-mailgun
```
## Usage
```php
$mg = \Mailgun\Mailgun::create('api_key');
$domain = 'mg.example.com';
$from = 'Alice ';
$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
```yaml
# config/packages/mailgun.yaml
services:
Mailgun\Mailgun:
class: Mailgun\Mailgun
factory: ['Mailgun\Mailgun', create]
arguments: ['%env(MAILGUN_API_KEY)%']
```
```yaml
# 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 # from
- [bob@foo.bar.com] # to
- '[Monolog] Error Report' # subject
```
```
# .env
MAILGUN_API_KEY=api_key
```
### Other
Feel free to send me a PR🙏