hitraa / openforge-mailer
Lightweight PHP SMTP Mailer with HTML, attachments, tracking pixel, and read receipt support.
Requires
- php: >=8.2
README
A lightweight, dependency-free PHP SMTP Mailer with support for:
- ๐ค Sending plain text and HTML emails
- ๐ Attachments
- ๐๏ธโ๐จ๏ธ Tracking pixel (read/open tracking)
- โ SMTP-level read receipt requests (RCPT NOTIFY)
- ๐ก๏ธ TLS / SSL / STARTTLS support
- ๐ ๏ธ Fallback to native
mail()
on failure - ๐ Debug mode for troubleshooting
๐ Features
- โ Simple API, single class
- ๐ฆ No external dependencies
- ๐ฌ Rich content: Plain text & HTML
- ๐ Attach multiple files
- ๐ Secure with SSL, TLS, or STARTTLS
- ๐๏ธ Tracking pixel integration with your server
- ๐จ Read receipt notification via SMTP
RCPT TO NOTIFY
- โ๏ธ Fallback to native
mail()
if SMTP fails (optional) - ๐งช Debug output for SMTP commands
๐ Example Use Cases
- โ Transactional email sending (invoices, alerts)
- ๐ข Email marketing campaigns (with tracking)
- ๐ฉ Application-based notifications
- ๐งช Development/testing mail delivery
- ๐๏ธ Track when an important email is read
๐ฆ Installation
Copy the Mailer.php
file to your project.
Alternatively, if you're using Composer:
composer require hitraa/openforge-mailer
๐ Directory Structure
openforge-mailer/
โโโ src/
โ โโโ Mailer.php
โโโ examples/
โ โโโ basic-send.php
โ โโโ track.php
โโโ composer.json
โโโ LICENSE
โโโ README.md
๐ Usage
1. Basic email
require_once 'vendor/autoload.php'; use OpenForge\Mailer\Mailer; $mail = new Mailer('smtp.yourhost.com', 'your@email.com', 'password'); $mail->setFrom('Your Name <your@email.com>') ->setRecipient('to@example.com') ->setSubject('Hello!') ->setBody('This is the plain-text version.') ->setHTMLBody('<h1>Hello!</h1><p>This is the HTML version.</p>'); echo $mail->send();
2. With attachments
$mail->setAttachment('/path/to/file.pdf');
3. With tracking pixel
$mail->enableTrackingPixel('https://yourdomain.com/track.php');
Your endpoint should log or store open events using query params like
?message_id=...&email=...
4. SMTP read receipt (SMTP DSN) behavior
Enabling read receipts:
$mail->requestReadReceipt(true);
This adds NOTIFY=SUCCESS,FAILURE,DELAY
in RCPT TO
, and the recipient's mail server will notify (if supported).
Also adds optional headers:
Disposition-Notification-To
Return-Receipt-To
X-Confirm-Reading-To
Note: Behavior depends on recipient's server & client.
5. Fallback to PHP mail()
if SMTP fails
$mail->allowFallbackToMail(true);
6. With custom message id prefix
$mail->setMessageIdPrefix('track-');
7. With multiple recipients
$mail->setRecipient(['one@example.com', 'two@example.com']);
Parse RFC email formats
Supports:
Name <email@example.com>
"Name" <email@example.com>
email@example.com
๐ Debugging
Enable SMTP-level debug messages:
$mail->enableDebug(true);
This will print the SMTP command flow.
๐ Example File
- ๐
examples/basic-send.php
โ Full example with HTML, text, attachment. - ๐
examples/track.php
โ Tracking pixel handler.
๐ SMTP Security Options
Default port | Option | Description | Mailer constant |
---|---|---|---|
587 | tls |
Default (STARTTLS) | Mailer::SECURE_TLS |
465 | ssl |
SSL connection | Mailer::SECURE_SSL |
587 | starttls |
Explicit STARTTLS | Mailer::SECURE_STARTTLS |
๐ก License
Released under the MIT License
๐จโ๐ป Author
Made with โค๏ธ by Harshal Khairnar Founder, Hitraa Technologies ๐ง harshal@hitraa.com
๐ค Contributions
Feel free to fork and submit pull requests. All improvements are welcome!
โ ๏ธ Disclaimer
This library is designed for educational and production-ready purposes. Use responsibly when tracking user interactions.