apeli / apelimailers
A lightweight, dependency-free PHP email library with SMTP, templating, queues, and analytics
Fund package maintenance!
Lipia Online
Requires
- php: ^8.1
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
Requires (Dev)
- mockery/mockery: ^1.4
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.7
- vimeo/psalm: ^5.4
Suggests
- ext-curl: Alternative for webhook delivery
- guzzlehttp/guzzle: Required for SendGrid/Mailgun webhooks
- predis/predis: For Redis queue support
- twig/twig: For template rendering support
This package is auto-updated.
Last update: 2025-05-05 07:35:32 UTC
README
📧 Lightweight PHP email library with SMTP, queues, and analytics
Overview
ApeliMailers is a PHP email library providing SMTP support, email queuing capabilities, and analytics. It's designed for developers who need a lightweight, flexible solution for handling email operations.
Features
- SMTP Support: Send emails via SMTP with TLS/SSL encryption
- Multiple Transport Options: Support for SMTP, Sendmail, and custom transports
- Email Analytics: Track email performance metrics
- Security-Focused: Built with security best practices
- Configurable: Adaptable to various email service providers
- Extensible Architecture: Create custom transport adapters
Installation
composer require apeli/apelimailers
Basic Usage
<?php require __DIR__ . '/vendor/autoload.php'; use ApeliMailers\Core\Mailer; use ApeliMailers\Transport\SmtpTransport; // Configure transport $transport = new SmtpTransport( 'smtp.example.com', 587, 'username', 'password', 'tls' ); // Initialize mailer $mailer = new Mailer($transport); // Create and send message $message = $mailer->createMessage() ->from('sender@example.com', 'Sender Name') ->to('recipient@example.com', 'Recipient Name') ->subject('Hello from ApeliMailers') ->html('<h1>Welcome!</h1><p>This is an email sent with ApeliMailers.</p>'); $result = $mailer->send($message);
Configuration
Transport Options
SMTP Transport
$transport = new SmtpTransport( 'smtp.example.com', // Host 587, // Port 'username', // Username 'password', // Password 'tls', // Encryption: 'tls', 'ssl', or null false // Debug mode (optional) );
Sendmail Transport
use ApeliMailers\Transport\SendmailTransport; $transport = new SendmailTransport('/usr/sbin/sendmail -bs');
Environment Configuration
Create a .env
file in your project root:
MAIL_HOST=smtp.example.com
MAIL_PORT=587
MAIL_USERNAME=username
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
Load configuration in your code:
<?php require __DIR__ . '/vendor/autoload.php'; $dotenv = Dotenv\Dotenv::createImmutable(__DIR__); $dotenv->load(); $transport = new SmtpTransport( $_ENV['MAIL_HOST'], $_ENV['MAIL_PORT'], $_ENV['MAIL_USERNAME'], $_ENV['MAIL_PASSWORD'], $_ENV['MAIL_ENCRYPTION'] );
Adding Attachments
$message->addAttachment('/path/to/file.pdf', 'document.pdf');
Managing Recipients
$message->to('recipient@example.com', 'Recipient Name') ->cc('cc@example.com', 'CC Recipient') ->bcc('bcc@example.com', 'BCC Recipient') ->replyTo('reply@example.com', 'Reply Handler');
License
ApeliMailers is open-source software licensed under the MIT license.