Componette

Componette

filips123

filips123 / MonologPHPMailer v2.0.0

PHPMailer handler for Monolog

download-cloud-line composer require filips123/monolog-phpmailer

MonologPHPMailer

version downloads license php build coverage quality

MonologPHPMailer is a PHPMailer handler for Monolog. It enables you to send logs to emails with PHPMailer.

Installation

Requirements

MonologPHPMailer requires PHP 8.1 or higher, Monolog 3.x, and PHPMailer 6.x.

Using Composer

The recommended way to install MonologPHPMailer is with Composer, a dependency manager for PHP.

You should just add filips123/monolog-phpmailer to your project dependencies in composer.json. It will also install Monolog and PHPMailer, but it is recommended to add them manually to composer.json.

{
    "require": {
        "monolog/monolog": "^3.0",
        "phpmailer/phpmailer": "^6.0",
        "filips123/monolog-phpmailer": "^2.0"
    }
}

Do not forget to run composer install and add require 'vendor/autoload.php'; to your main script.

Manually Installation

Alternatively, you could download all files in the src directory from GitHub and then manually include them in your script. You also have to install Monolog and PHPMailer manually.

Usage

You should just add the handler MonologPHPMailer\PHPMailerHandler to your logger. Its first argument must be a PHPMailer instance.

Example

<?php

use MonologPHPMailer\PHPMailerHandler;

use Monolog\Formatter\HtmlFormatter;
use Monolog\Logger;
use Monolog\Processor\IntrospectionProcessor;
use Monolog\Processor\MemoryUsageProcessor;
use Monolog\Processor\WebProcessor;

use PHPMailer\PHPMailer\PHPMailer;

require __DIR__ . '/vendor/autoload.php';

$mailer = new PHPMailer(true);
$logger = new Logger('logger');

$mailer->isSMTP();
$mailer->Host = 'smtp.example.com';
$mailer->SMTPAuth = true;
$mailer->Username = 'server@example.com';
$mailer->Password = 'password';

$mailer->setFrom('server@example.com', 'Logging Server');
$mailer->addAddress('user@example.com', 'Your Name');

$logger->pushProcessor(new IntrospectionProcessor);
$logger->pushProcessor(new MemoryUsageProcessor);
$logger->pushProcessor(new WebProcessor);

$handler = new PHPMailerHandler($mailer);
$handler->setFormatter(new HtmlFormatter);

$logger->pushHandler($handler);

$logger->error('Error!');
$logger->alert('Something went wrong!');

Versioning

This library uses SemVer SemVer for versioning. For the versions available, see the tags on this repository.

License

This library is licensed under the MIT license. See the LICENSE file for details.

  • v2.0.0 MonologPHPMailer 2.0.0

    Added

    • Support for Monolog v3.

    Changed

    • The minimum required PHP version is now 8.1.
    • The project now uses GitHub Actions for testing.

    Removed

    • Support for Monolog v1 and v2.
    • Support for PHP < 8.1.
  • v1.0.3 MonologPHPMailer 1.0.3

    Fixed

    • Lock PHPUnit versions.
    • Update Travis CI PHP versions.
  • v1.0.2 MonologPHPMailer 1.0.2

    Fixed

    • Coverage report with merging clovers of Monolog 1.x and 2.x.
    • Documentation of manual installation.
  • v1.0.1 MonologPHPMailer 1.0.1

    Added

    • Support for Monolog 2.x.
  • v1.0.0 MonologPHPMailer 1.0.0

    Added

    • First version of package.
    • Handler for Monolog 1.x.
bar-chart-fill

Statistics

download-cloud-fill
35329
star-fill
12
bug-fill
0
flashlight-fill
165d
price-tag-2-line

Badges

guide-fill

Dependencies

php (>= 5.5.0)
monolog/monolog (^1.0|^2.0@dev)
Componette Componette felix@nette.org