PHP Classes

PHPMailer Logging with Monolog: Log email sent via PHPMailer using Monolog

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (13)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 101 All time: 9,691 This week: 189Up
Version License PHP version Categories
monolog-phpmailer 1.0MIT/X Consortium ...5.5.0Email, PHP 5, Logging


Filip ?


This package can log email sent via PHPMailer using Monolog.

It provides a logger handler class that can take a PHPMailer object already configured to send email messages.

The handler class object can be passed to Monolog to define the way the information about the messages that are sent is used to generate the log output.

Innovation Award
PHP Programming Innovation award nominee
October 2018
Number 2

Prize: PHP Tools for Visual Studio Personal license
PHPMailer is a popular package for sending email. Monolog is a popular package for generating logs for the current application activity.

This package provides a brigde between PHPMailer and Monolog by passing the necessary information about mailing activity, so all actions records can be sent to logs.

Manuel Lemos
Picture of Filip Štamcar
  Performance   Level  
Name: Filip Štamcar <contact>
Classes: 3 packages by
Country: Slovenia Slovenia
Age: ???
All time rank: 408011 in Slovenia Slovenia
Week rank: 578 Up2 in Slovenia Slovenia Up
Innovation award
Innovation award
Nominee: 1x



[![Latest Stable Version][icon-stable-version]][link-packagist] [![Latest Untable Version][icon-unstable-version]][link-packagist] [![Total Downloads][icon-downloads]][link-packagist] [![License][icon-license]][link-license] [![PHP][icon-php]][link-php]

[![Linux Build Status][icon-travis]][link-travis] [![Windows Build Status][icon-appveyor]][link-appveyor] [![Code Coverage][icon-coverage]][link-coverage] [![Code Quality][icon-quality]][link-quality]

MonologPHPMailer is a [PHPMailer][link-phpmailer] handler for [Monolog][link-monolog]. It enables you to send logs to emails with PHPMailer.



MonologPHPMailer requires [PHP][link-php] 5.5.0 or higher, [Monolog][link-monolog] 1.x or 2.x and [PHPMailer][link-phpmailer] 6.x.

Using Composer

The reccomended way to install MonologPHPMailer is with [Composer][link-composer], 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 reccomended to add them manually to composer.json.

    "require": {
        "monolog/monolog": "^1.0",
        "phpmailer/phpmailer": "^6.0",
        "filips123/monolog-phpmailer": "^1.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 directory [src][link-handlers] from GitHub and then manually include them in your script. You also have to install Monolog and PHPMailer manually.


You should just add handler MonologPHPMailer\PHPMailerHandler to your logger. It's first argument must be PHPMailer instance.



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->Host = '';
$mailer->SMTPAuth = true;
$mailer->Username = '';
$mailer->Password = 'password';

$mailer->setFrom('', 'Logging Server');
$mailer->addAddress('', 'Your Name');

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

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


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


This library uses [SemVer][link-semver] SemVer for versioning. For the versions available, see the [tags on this repository][link-tags].


This library is licensed under the MIT license. See the [LICENSE][link-license-file] file for details.

[icon-stable-version]: [icon-unstable-version]: [icon-downloads]: [icon-license]: [icon-php]: [icon-travis]: [icon-appveyor]: [icon-coverage]: [icon-quality]:

[link-packagist]: [link-license]: [link-php]: [link-travis]: [link-appveyor]: [link-coverage]: [link-quality]:

[link-monolog]: [link-phpmailer]: [link-composer]: [link-handlers]: [link-semver]: [link-tags]: [link-license-file]:

  • code.jpg
  • email.jpg
  Files folder image Files  
File Role Description
Files folder imagesrc (3 files)
Files folder imagetests (2 files)
Accessible without login Plain text file .editorconfig Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml.dist Data Auxiliary data
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file Doc. Documentation

  Files folder image Files  /  src  
File Role Description
  Accessible without login Plain text file PHPMailerHandler.php Aux. Auxiliary script
  Plain text file PHPMailerHandler1.php Class Class source
  Plain text file PHPMailerHandler2.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file PHPMailerHandlerTest.php Class Class source
  Plain text file TestCase.php Class Class source 131KB
Downloadmonolog-phpmailer-2018-10-08.tar.gz 130KB
Install with ComposerInstall with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
PHPMailer Download .zip .tar.gz It is using it for sending emails. Required
 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,691
This week:189Up