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.
composer require marko/mail marko/mail-smtpSending Mail
Section titled “Sending Mail”<?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); }}Available Transports
Section titled “Available Transports”| Package | Transport | Best For |
|---|---|---|
marko/mail-smtp | SMTP server | Production |
marko/mail-log | Log file | Development, testing |
Switching Transports
Section titled “Switching Transports”use Marko\Mail\Contracts\MailerInterface;use Marko\Mail\Log\LogMailer;
return [ 'bindings' => [ MailerInterface::class => LogMailer::class, ],];Next Steps
Section titled “Next Steps”- Queues — send mail in the background
- Events — trigger mail from events
- Mail package reference — full API details