hitraa/openforge-mailer

Lightweight PHP SMTP Mailer with HTML, attachments, tracking pixel, and read receipt support.

v1.0.0 2025-06-15 14:42 UTC

This package is auto-updated.

Last update: 2025-06-15 15:14:04 UTC


README

Latest Version License PHP Version

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

๐Ÿ” 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.