Skip to content
MaatifyPublic

About

PHP library for rendering Twig email templates and sending transactional emails via authenticated SMTP (PHPMailer), with customizable subjects and SMTP acceptance reporting.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Mailer

Maatify.dev

Status Version PHP License PHPStan

Packagist Monthly Downloads Total Downloads Maatify Ecosystem

Usage Guide Examples Package Reference Changelog Security Policy Contributing

PHP library that renders Twig e-mail templates supplied by your application and sends them through SMTP with PHPMailer, reporting whether the SMTP server accepted each message.


Key Features

  • Renders the Twig templates you provide (the library ships none) and sends the result as an HTML message with a plain-text alternative.
  • Sends through SMTP with PHPMailer over implicit TLS and returns true only when the SMTP server accepted the message.
  • Ready-made messages: confirmation code, confirmation and password-reset links, temporary password, plain message, and a contact form that forwards a visitor's message to the site and acknowledges it.
  • Subject lines you can customize through an explicit contract; the library owns sensible defaults.
  • Logs failures through maatify/logger as fixed markers and exception metadata, never recipient addresses, subjects or message content.

Requirements

  • PHP >=8.4.27 <8.5.0 || >=8.5.12 <8.6.0 with ext-openssl.
  • phpmailer/phpmailer ^6.10, twig/twig ^3.27 and maatify/logger ^5.0 || ^7.0.
  • An SMTP server that accepts authenticated connections over implicit TLS, and a directory of Twig templates.

The authoritative constraints are in composer.json.

Installation

composer require maatify/mailer

With the constraint ^5.0 an existing project stays on 5.x, so to move an existing project to 6.x use composer require 'maatify/mailer:^6.0' --with-all-dependencies. 6.0.0 uses new namespaces and sends through SMTP only; see Upgrade notes.

Quick Usage

<?php

use Maatify\Mailer\Service\Mailer;

require 'vendor/autoload.php';

// The settings (SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASS, SMTP_FROM_MAIL, SMTP_FROM_NAME,
// EMAIL_SITE_URL, EMAIL_SITE_LOGO, EMAIL_SITE_NAME) are read from $_ENV.
$mailer = new Mailer('[email protected]', 'User Name', '', __DIR__ . '/templates/email');

if ($mailer->ConfirmCode('482913')) {
    // the SMTP server accepted the message
} else {
    // it was not accepted, or could not be sent
}

The Usage Guide walks through each call as Input → Public Call → Result → Boundary.

Public Runtime API

Type Role
Maatify\Mailer\Service\Mailer Entry point: the constructor, obj(), reInitiateSender(), twigLoader() and the send methods ConfirmCode(), ConfirmUserLink(), ConfirmCustomerLink(), ConfirmDashboardLink(), ResetPassDashboardLink(), TempPassword(), Message() and AdminMessage().
Maatify\Mailer\Contract\SubjectProviderInterface Lets your application choose subject lines.
Maatify\Mailer\Enum\MailSubjectEnum The messages whose subject the library chooses, with their default subjects.
Maatify\Mailer\Adapter\MailerSender Abstract SMTP sender that Mailer extends; its protected members are the documented extension point.

The complete inventory, signatures and guarantees are in the Package Reference.

Critical Runtime Behavior

  • A send method returns true only when the SMTP server accepted the message; it never retries.
  • AdminMessage() sends two messages (to the site, then an acknowledgement to the visitor) and restores the object's recipient afterwards.
  • Settings are read from $_ENV, not from getenv() or .env files.

Exception and Error Propagation

Where a failure surfaces depends on where it occurs. A missing setting that is read before sending (for example SMTP_REPLY_MAIL in the constructor, SITE_URL in the link methods, SMTP_FROM_* in AdminMessage()), a missing template directory and an exception thrown by your subject provider reach your code. Template errors and problems with the SMTP settings or connection while sending are caught, logged without recipient data and returned as false. The Package Reference has the full table.

Security and Trust Boundaries

  • The SMTP credentials belong to your application: keep them in your own secret storage and never commit them. The library does not store or rotate them.
  • Log entries contain fixed markers and exception metadata only, never addresses, subjects, message content or exception messages.
  • The library does not change PHPMailer's TLS verification: the server's certificate must be valid for SMTP_HOST.
  • Report a vulnerability privately, as described in SECURITY.md; do not use public issues.

Examples

Runnable examples are in examples/: a confirmation code, custom subject lines, and a contact form, with a working template set. CI executes them against a local SMTP stand-in.

Documentation

Quality Status

Verified in CI on PHP 8.4 and 8.5, and on the lowest supported dependencies:

  • PHPStan at level max.
  • Regression and system test suites; every send runs against a local SMTP stand-in with implicit TLS, so no real mail is sent.
  • The logging calls run against maatify/logger 5.0.1, 5.1.0, 5.1.2 and 7.0.0, which represent the supported ^5.0 || ^7.0 range.
  • A consumer harness that installs the package from the committed tree into a clean Composer project and sends mail through its public API.
  • Smoke execution of the examples, and an inspection of the distribution archive and its document links.
  • composer audit with abandoned packages treated as failures.

These checks prove the implemented contract against a deterministic local SMTP server. They do not prove the behavior of a particular live mail provider.

Development and Testing

composer update
composer analyse
composer test
scripts/ci/verify.sh latest

scripts/ci/verify.sh runs the same checks as CI. See CONTRIBUTING.md.

Upgrade Notes

6.0.0 moves the classes to the canonical namespaces, sends through SMTP only, and replaces the application class App\Assist\Config\MailerConfig with an injected subject provider:

// 5.x
use Maatify\Mailer\Mailer;

// 6.0.0
use Maatify\Mailer\Service\Mailer;

The complete upgrade steps are in the Changelog.

License

Proprietary. See LICENSE.

Author

Engineered by Mohamed Abdulalim (@megyptm)
Backend Lead & Technical Architect
https://www.maatify.dev


About

PHP library for rendering Twig email templates and sending transactional emails via authenticated SMTP (PHPMailer), with customizable subjects and SMTP acceptance reporting.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages