devinci-it/brevomailer

Brevo SMTP Mailer Package

Maintainers

Package info

github.com/devinci-it/devinci-it-brevomailer

pkg:composer/devinci-it/brevomailer

Transparency log

Statistics

Installs: 13

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-08-10 10:37 UTC

This package is auto-updated.

Last update: 2026-08-10 10:38:02 UTC


README

A modern, modular, and strictly object-oriented SMTP library for PHP 8.1+. Designed to provide a clean, dry, and decoupled interface for sending emails via Brevo (or any SMTP provider) while maintaining environment agnosticism.

Features

  • Strictly OOP: Decoupled architecture using Interfaces and Value Objects.
  • Compose Method Pattern: Small, readable, single-responsibility methods.
  • Environment Agnostic: No hardcoded .env logic within the core service.
  • Sender Overrides: Easily swap "From" identity on a per-email basis.
  • CC / BCC Support: Add carbon-copy and blind-carbon-copy recipients via the DTO or the fluent builder.
  • Global Helper: Optional global mailer() helper for easy access.
  • Interactive Env Setup: A bin/brevomailer-init CLI prompts for credentials and runs a live SMTP connection test.

Installation

composer require devinci-it/brevo-mailer phpmailer/phpmailer vlucas/phpdotenv

Quick Start

use DevinciIT\BrevoMailer\MailerFactory;
use DevinciIT\BrevoMailer\DTO\EmailMessage;

// 1. Initialize
$mailer = MailerFactory::createFromEnv(__DIR__);

// 2. Send
$mailer->send(new EmailMessage(
    to: 'client@example.com',
    subject: 'Hello World',
    htmlBody: '<h1>Test Email</h1>'
));

CC / BCC

Pass cc / bcc to EmailMessage directly, or use the fluent EmailBuilder. Each accepts a single email, a list of emails, or an email => name map — multiple calls accumulate.

use DevinciIT\BrevoMailer\DTO\EmailMessage;

$mailer->send(new EmailMessage(
    to: 'client@example.com',
    subject: 'Hello World',
    htmlBody: '<h1>Test Email</h1>',
    cc: ['manager@example.com' => 'Manager Name'],
    bcc: ['audit@example.com']
));
use DevinciIT\BrevoMailer\Builders\EmailBuilder;

$message = (new EmailBuilder())
    ->to('client@example.com')
    ->subject('Hello World')
    ->view(__DIR__ . '/templates/welcome.php')
    ->cc('manager@example.com')
    ->cc('legal@example.com', 'Legal Team') // accumulates
    ->bcc(['audit@example.com', 'archive@example.com'])
    ->build();

$mailer->send($message);

Malformed addresses are dropped when sending and cause validate() to fail; each address is also stripped of CR/LF to prevent header-injection.

Interactive Environment Setup

bin/brevomailer-init walks you through the critical SMTP variables (MAIL_HOST, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD, MAIL_FROM_ADDRESS, MAIL_FROM_NAME, MAIL_ENCRYPTION), writes/updates .env in your current working directory, then performs a live SMTP connection test (isHealthy()) and reports the result.

# Installed as a dependency:
php vendor/bin/brevomailer-init

# Working within this repo directly:
php bin/brevomailer-init

Run it from your project root so .env is written in the right place. Existing values in .env are used as defaults (press Enter to keep them); the password prompt hides input on Unix-like shells and the written file is chmod'd to 0600.