The LoggingCourier is not designed to be used in a production system, but it can act as a drop-in testing implementation, allowing developers to build content and log it to their local systems, without delivering emails. This can be helpful in cases where the email might contain important information, like a generated password reset token.
This package is included in the core
quartzy/courier and no other dependencies are necessary.
composer require quartzy/courier
<?php use Courier\LoggingCourier; use PhpEmail\Content\TemplatedContent; use PhpEmail\EmailBuilder; use Psr\Log\NullLogger; // Be sure to create your own logger implementation and pass it into the courier. $courier = new LoggingCourier(new NullLogger()); $email = EmailBuilder::email() ->from('email@example.com') ->to('firstname.lastname@example.org') ->replyTo('email@example.com', 'Your Sales Rep') ->withSubject('Welcome!') ->withContent(new TemplatedContent('my_email', ['testKey' => 'value'])) ->build(); $courier->deliver($email);