An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# monolog-mailgun

[![Build Status](https://travis-ci.org/ttskch/monolog-mailgun.svg?branch=master)](https://travis-ci.org/ttskch/monolog-mailgun)
[![Latest Stable Version](https://poser.pugx.org/ttskch/monolog-mailgun/version)](https://packagist.org/packages/ttskch/monolog-mailgun)
[![Total Downloads](https://poser.pugx.org/ttskch/monolog-mailgun/downloads)](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🙏