Git Product home page Git Product logo

monologphpmailer's Introduction

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 = '[email protected]';
$mailer->Password = 'password';

$mailer->setFrom('[email protected]', 'Logging Server');
$mailer->addAddress('[email protected]', '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.

monologphpmailer's People

Contributors

filips123 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

skizzo hardjunior

monologphpmailer's Issues

Make compatible with monolog v3 ?

Hey there and thanks for this nice PHPMailer-Handler for monolog.
Is this REPO still "alive" ?

Is there any chance to make this work wiht the latest release of monolog (Version 3) ?

Here's my current quick&dirty solution, which works with monolog 3.4

  • I use /src/PHPMailerHandler2.php which I renamed to PHPMailerHandler.php
  • I renamed the class inside PHPMailerHandler2.php to PHPMailerHandler
  • I removed namespace MonologPHPMailer; in the top section of that file

So maybe all that's required is to edit composer.json to also "allow" v3.x" of monolog, in order to make it compatible ??
But I am not sure about that!

Looking forward to your answer,
Manfred

Works on PHP 5.3.28

Hi, I took your code (PHPMailerHandler1.php) and made it to work on PHP 5.3.28 without any sensible changes.

Other versions I used:
PHP 5.3.28
Monolog 1.26.0
PHPMailer 5.2.28

Just for your possible concern.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.