PHPackages                             websitesql/mailer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. websitesql/mailer

ActiveFramework[Mail &amp; Notifications](/categories/mail)

websitesql/mailer
=================

A simple PHP framework for sending emails with PHPMailer and Plates.

v1.0.0(1y ago)03MITPHPPHP ^8.2

Since Apr 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/websitesql/mailer)[ Packagist](https://packagist.org/packages/websitesql/mailer)[ Docs](https://www.websitesql.com)[ RSS](/packages/websitesql-mailer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

WebsiteSQL Mail
===============

[](#websitesql-mail)

A fluent, chainable PHP email library supporting multiple mail drivers (PHP mail, SMTP, log) with HTML/plain text content and template support using League/Plates.

Installation
------------

[](#installation)

```
composer require websitesql/mail
```

Configuration
-------------

[](#configuration)

The `MailProvider` class requires an array of configuration options:

```
$mailConfig = [
    // Required
    'driver' => 'smtp', // Options: 'mail', 'smtp', 'log'
    'from' => 'no-reply@example.com', // Sender email address
    'from_name' => 'My Application', // Sender name

    // Required for template support
    'template_path' => __DIR__ . '/templates', // Path to email templates

    // Required for SMTP
    'smtp_host' => 'smtp.example.com',
    'smtp_port' => 587, // Common ports: 25, 465, 587
    'smtp_username' => 'username',
    'smtp_password' => 'password',

    // Optional
    'debug' => false, // Enable debugging (for SMTP)
];
```

Basic Usage
-----------

[](#basic-usage)

The library uses a fluent interface with method chaining:

```
// Create a mail provider instance
$mailer = new \WebsiteSQL\Mailer\MailProvider($mailConfig);

// Example 1: Send HTML email
$mailer->html('Hello WorldThis is a test email.')
       ->subject('Test HTML Email')
       ->send('recipient@example.com');

// Example 2: Send plain text email
$mailer->plain('Hello World. This is a test email.')
       ->subject('Test Plain Text Email')
       ->send('recipient@example.com');

// Example 3: Send email with both HTML and plain text
$mailer->html('Hello WorldThis is a test email.')
       ->plain('Hello World. This is a test email.')
       ->subject('Test Multipart Email')
       ->send('recipient@example.com');

// Example 4: Use a template
$mailer->template('welcome', ['name' => 'John Doe'])
       ->subject('Welcome to Our Site')
       ->send('john.doe@example.com');
```

API Reference
-------------

[](#api-reference)

### Constructor

[](#constructor)

```
public function __construct(array $options)
```

Creates a new instance of the `MailProvider` class.

**Parameters:**

- `$options` (array): Configuration options for the mail provider

### Methods

[](#methods)

#### `template(string $template, array $data = []): self`

[](#templatestring-template-array-data---self)

Sets the email content using a template.

**Parameters:**

- `$template` (string): Template name (without file extension)
- `$data` (array): Data to pass to the template

**Returns:** Self (for method chaining)

**Throws:** `RuntimeException` if template path is not configured or template rendering fails

#### `html(string $html): self`

[](#htmlstring-html-self)

Sets the HTML content of the email.

**Parameters:**

- `$html` (string): HTML content

**Returns:** Self (for method chaining)

#### `plain(string $text): self`

[](#plainstring-text-self)

Sets the plain text content of the email.

**Parameters:**

- `$text` (string): Plain text content

**Returns:** Self (for method chaining)

#### `subject(string $subject): self`

[](#subjectstring-subject-self)

Sets the subject of the email.

**Parameters:**

- `$subject` (string): Email subject

**Returns:** Self (for method chaining)

#### `send(string $to): bool`

[](#sendstring-to-bool)

Sends the email to the specified recipient.

**Parameters:**

- `$to` (string): Email recipient

**Returns:** Boolean indicating success or failure

**Throws:** `RuntimeException` if required fields are not set

Email Drivers
-------------

[](#email-drivers)

### PHP mail()

[](#php-mail)

Uses PHP's built-in `mail()` function to send emails. Configure with:

```
$config = [
    'driver' => 'mail',
    'from' => 'sender@example.com',
    'from_name' => 'Sender Name'
];
```

### SMTP

[](#smtp)

Uses PHPMailer to send emails via SMTP. Configure with:

```
$config = [
    'driver' => 'smtp',
    'from' => 'sender@example.com',
    'from_name' => 'Sender Name',
    'smtp_host' => 'smtp.example.com',
    'smtp_port' => 587, // 25, 465, or 587
    'smtp_username' => 'username',
    'smtp_password' => 'password',
    'debug' => false // Set to true for debugging
];
```

Port 465 uses implicit SSL/TLS encryption, while port 587 uses STARTTLS.

### Log

[](#log)

Logs emails to the error log instead of sending them. Useful for development and testing. Configure with:

```
$config = [
    'driver' => 'log'
];
```

Templates
---------

[](#templates)

The library uses [League/Plates](https://platesphp.com/) for templating. Create templates in your template directory:

```
// templates/welcome.php
Welcome, !
Thank you for registering.
```

Then use them:

```
$mailer->template('welcome', ['name' => 'John Doe'])
       ->subject('Welcome')
       ->send('john@example.com');
```

Exception Handling
------------------

[](#exception-handling)

The library throws `RuntimeException` for configuration errors and other issues:

```
try {
    $mailer->html('Hello')
           ->subject('Test')
           ->send('recipient@example.com');
} catch (RuntimeException $e) {
    // Handle the error
    echo "Error: " . $e->getMessage();
}
```

Complete Example
----------------

[](#complete-example)

```
// Create configuration
$config = [
    'driver' => 'smtp',
    'from' => 'no-reply@myapp.com',
    'from_name' => 'My Application',
    'template_path' => __DIR__ . '/templates',
    'smtp_host' => 'smtp.myapp.com',
    'smtp_port' => 587,
    'smtp_username' => 'smtp_user',
    'smtp_password' => 'smtp_password'
];

// Create mailer
$mailer = new \WebsiteSQL\Mailer\MailProvider($config);

// Send a welcome email
try {
    $mailer->template('welcome', [
              'username' => 'johndoe',
              'app_name' => 'My Application',
              'login_url' => 'https://myapp.com/login'
           ])
           ->subject('Welcome to My Application')
           ->send('john.doe@example.com');

    echo "Email sent successfully!";
} catch (RuntimeException $e) {
    echo "Failed to send email: " . $e->getMessage();
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance47

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

399d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/280e4b985f922abd667a75c49aee0c176202dcbf84464fd50de0cd9328092e60?d=identicon)[alantiller](/maintainers/alantiller)

---

Top Contributors

[![alantiller](https://avatars.githubusercontent.com/u/26198238?v=4)](https://github.com/alantiller "alantiller (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/websitesql-mailer/health.svg)

```
[![Health](https://phpackages.com/badges/websitesql-mailer/health.svg)](https://phpackages.com/packages/websitesql-mailer)
```

###  Alternatives

[ivantcholakov/codeigniter-phpmailer

A CodeIgniter 3 compatible email-library powered by PHPMailer.

25313.9k](/packages/ivantcholakov-codeigniter-phpmailer)[markguinn/silverstripe-email-helpers

Silverstripe extension containing SMTP mailer class and some other classes for HTML emails

3145.4k1](/packages/markguinn-silverstripe-email-helpers)[msp/smtp

SMTP with PHPMailer

2129.4k](/packages/msp-smtp)[nfephp-org/sped-mail

API para geração e envio dos emails relacionados com o SPED.

1123.7k](/packages/nfephp-org-sped-mail)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
