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/src/Service/NotificationService.php
<?php
declare(strict_types=1);
namespace App\Blog\Service;
use Marko\Mail\Contracts\MailerInterface;
use Marko\Mail\Message;
readonly class NotificationService
{
public function __construct(
private MailerInterface $mailer,
) {}
public function notifyAuthor(
string $email,
string $postTitle,
): void {
$message = Message::create()
->to($email)
->subject("Your post '{$postTitle}' was published")
->text('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\Contracts\MailerInterface;
use Marko\Mail\Log\LogMailer;
return [
'bindings' => [
MailerInterface::class => LogMailer::class,
],
];