Skip to content

Mail

Marko’s mail system provides a clean interface for sending emails with pluggable transports. Code against MailerInterface and swap between SMTP, log, or custom transports by changing a single binding.

Terminal window
composer require marko/mail marko/mail-smtp
app/blog/Service/NotificationService.php
<?php
declare(strict_types=1);
namespace App\Blog\Service;
use Marko\Mail\MailerInterface;
use Marko\Mail\Message;
class NotificationService
{
public function __construct(
private readonly MailerInterface $mailer,
) {}
public function notifyAuthor(string $email, string $postTitle): void
{
$message = new Message(
to: $email,
subject: "Your post '{$postTitle}' was published",
body: "Congratulations! Your post is now live.",
);
$this->mailer->send($message);
}
}
PackageTransportBest For
marko/mail-smtpSMTP serverProduction
marko/mail-logLog fileDevelopment, testing
module.php
use Marko\Mail\TransportInterface;
use Marko\Mail\Log\LogTransport;
return [
'bindings' => [
TransportInterface::class => LogTransport::class,
],
];