Search by

aiub-computer-club / local-smtp-mailer

rionislam

Zero-dependency PHP socket mailer and WordPress drop-in fix for servers where native mail() is disabled.

Package info

github.com/AIUB-Computer-Club/local-smtp-mailer

pkg:composer/aiub-computer-club/local-smtp-mailer

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-11-27 14:47 UTC

This package is auto-updated.

Last update: 2026-11-27 14:48:40 UTC


README

A lightweight, zero-dependency PHP socket mailer and WordPress drop-in solution designed for cPanel, Linux, and hardened web servers where native PHP mail() has been disabled in php.ini (disable_functions).

The Problem

On many production hosting environments and hardened cPanel servers, server administrators disable the native mail() function to prevent unauthorized script spamming:

disable_functions = exec,system,shell_exec,mail

When this occurs:

  • WordPress wp_mail() crashes or fails silently.
  • Form plugins (Forminator, Contact Form 7, Elementor) cannot send notification emails.
  • Custom PHP and web applications throw fatal errors when attempting to dispatch emails.
  • Third-party SMTP plugins typically demand external API keys, dedicated accounts, or recurring subscription fees.

However, almost all cPanel/Linux servers run a local Mail Transfer Agent (Exim or Postfix) listening on 127.0.0.1:25. The local MTA automatically signs outgoing messages with your domain's SPF and DKIM keys without requiring third-party credentials.

Features

  • Zero External Dependencies: Built with pure PHP stream sockets (fsockopen).
  • WordPress Drop-In: Simply place in wp-content/mu-plugins/ for instant activation.
  • Custom PHP & Framework Ready: Includes a clean object-oriented class and procedural helper.
  • Native Server DKIM & SPF: Leverages the host server's local MTA for high inbox delivery rates.
  • RFC 5321 Compliant: Supports dot-stuffing and standard SMTP handshake sequences.

1. WordPress Setup (1-Click)

Copy wordpress/mailer-fix.php into your WordPress installation:

wp-content/
└── mu-plugins/
    └── mailer-fix.php

All outgoing emails sent via wp_mail() (including core notifications and plugins) will automatically route through 127.0.0.1:25.

Optional Configuration (wp-config.php)

You can customize sender details and ports in wp-config.php:

define( 'LOCAL_SMTP_HOST', '127.0.0.1' );
define( 'LOCAL_SMTP_PORT', 25 );
define( 'LOCAL_SMTP_FROM', 'noreply@yourdomain.com' );
define( 'LOCAL_SMTP_FROM_NAME', 'Your Site Name' );

2. Custom PHP Usage

Procedural Helper

require_once __DIR__ . '/src/LocalSmtpMailer.php';
require_once __DIR__ . '/src/helpers.php';

// Drop-in replacement for native mail()
local_mail(
    'user@example.com',
    'Registration Confirmation',
    'Thank you for registering.',
    ['Reply-To: support@yourdomain.com']
);

Object-Oriented Interface

use AIUBCC\Mailer\LocalSmtpMailer;

$mailer = new LocalSmtpMailer('127.0.0.1', 25);

[$success, $error] = $mailer->sendMail(
    'recipient@example.com',
    'Account Verification',
    '<h1>Welcome</h1><p>Your account is ready.</p>',
    ['Reply-To: contact@yourdomain.com'],
    'noreply@yourdomain.com',
    'ACC Team',
    true // isHtml
);

if (!$success) {
    echo "Delivery failed: " . $error;
}

3. Laravel Setup

In Laravel, native SMTP configuration already supports local relays with zero code:

Update your .env file:

MAIL_MAILER=smtp
MAIL_HOST=127.0.0.1
MAIL_PORT=25
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="noreply@yourdomain.com"
MAIL_FROM_NAME="${APP_NAME}"

Then clear the configuration cache:

php artisan config:clear

Project Structure

local-smtp-mailer/
├── src/
│   ├── LocalSmtpMailer.php    # Standalone socket client
│   └── helpers.php            # procedural local_mail() helper
├── wordpress/
│   └── mailer-fix.php         # Drop-in WordPress mu-plugin
├── examples/
│   ├── plain-php.php          # PHP usage examples
│   └── laravel.md             # Laravel configuration guide
├── composer.json              # Composer package descriptor
└── README.md

License

This project is licensed under the MIT License - authored by the AIUB Computer Club (ACC) R&D Team.