PHPackages                             monkeyscloud/monkeyslegion-mail - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. monkeyscloud/monkeyslegion-mail

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

monkeyscloud/monkeyslegion-mail
===============================

Mail integration package for the MonkeysLegion framework.

1.0.7(5mo ago)1988↑142.9%[1 PRs](https://github.com/MonkeysCloud/MonkeysLegion-Mail/pulls)2MITPHPPHP ^8.4

Since Jul 23Pushed 1mo agoCompare

[ Source](https://github.com/MonkeysCloud/MonkeysLegion-Mail)[ Packagist](https://packagist.org/packages/monkeyscloud/monkeyslegion-mail)[ RSS](/packages/monkeyscloud-monkeyslegion-mail/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (10)Versions (11)Used By (2)

MonkeysLegion Mail
==================

[](#monkeyslegion-mail)

[![PHP Version](https://camo.githubusercontent.com/2aed50cc19486e0407775311c22f530383b2791ca08b8c9583ebb80cb5e364e7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e342532422d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

A powerful, feature-rich mail package for the MonkeysLegion PHP framework, providing robust email functionality with DKIM signing, queue support, rate limiting, and elegant template rendering.

📋 What's Inside
---------------

[](#-whats-inside)

This comprehensive mail package includes everything you need for professional email handling:

### 🚀 **Getting Started**

[](#-getting-started)

- **Quick Installation**: Automated setup with scaffolding
- **Configuration**: Environment variables and driver setup
- **First Email**: Send your first email in minutes

### 📧 **Core Email Features**

[](#-core-email-features)

- **Multiple Transports**: SMTP, Sendmail, Mailgun, and Null drivers
- **Direct Sending**: Immediate email delivery
- **Queue System**: Background email processing with Redis
- **Rate Limiting**: Prevent spam and control sending limits

### 🛡️ **Security &amp; Authentication**

[](#️-security--authentication)

- **DKIM Signing**: Digital signatures for email authentication
- **SPF/DMARC Ready**: Compatible with modern email security
- **Raw Key Support**: Simplified DKIM key management

### 🎨 **Template System**

[](#-template-system)

- **Mailable Classes**: Object-oriented email composition
- **ML View Engine**: Powerful template rendering
- **Email Components**: Reusable UI components
- **Dynamic Content**: Data binding and conditional rendering

### ⚡ **Advanced Features**

[](#-advanced-features)

- **CLI Commands**: Command-line email management
- **Queue Management**: Job retry, failure handling
- **Logging**: Comprehensive PSR-3 compatible logging
- **Events**: Email lifecycle tracking

### 🔧 **Developer Tools**

[](#-developer-tools)

- **Make Commands**: Generate mail classes instantly
- **Testing Tools**: Test email sending without queues
- **Debug Mode**: Detailed logging and error reporting

---

🚀 Quick Start
-------------

[](#-quick-start)

### Installation

[](#installation)

```
# Install Monkeys Legion App
composer create-project --stability=dev \ monkeyscloud/monkeyslegion-skeleton my-app "dev-main"

# Publish configuration and scaffolding
php ml mail:install
```

### Basic Configuration

[](#basic-configuration)

Add these variables to your `.env` file:

```
# Basic SMTP Configuration
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_ENCRYPTION=tls

# OR Mailgun Configuration
MAILGUN_API_KEY=YOUR_MAILGUN_API_KEY
MAILGUN_DOMAIN=YOUR_MAILGUN_DOMAIN

# DKIM Configuration (Optional but Recommended)
MAIL_DKIM_PRIVATE_KEY=your-raw-private-key-without-headers
MAIL_DKIM_SELECTOR=default
MAIL_DKIM_DOMAIN=yourdomain.com

# Queue Configuration (Optional but required in queueing)
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
QUEUE_DEFAULT=emails

# A Global Configuration
MAIL_FROM_ADDRESS=your-email@gmail.com
MAIL_FROM_NAME="Your App Name"
```

### You can always check the mail.php config file to see all the available options you can set in your .env

[](#you-can-always-check-the-mailphp-config-file-to-see-all-the-available-options-you-can-set-in-your-env)

### Test Your Setup

[](#test-your-setup)

```
# Test email sending
php vendor/monkeyscloud/monkeyslegion-mail/bin/ml-mail.php mail:test your-email@example.com
```

---

📧 Sending Emails
----------------

[](#-sending-emails)

### Direct Sending

[](#direct-sending)

```
use MonkeysLegion\Mail\Mailer;

// Get mailer instance
/** @var Mailer */
$mailer = ML_CONTAINER->get(Mailer::class);

// Send immediately
$mailer->send(
    'user@example.com',
    'Welcome to Our App',
    'Welcome!Thanks for joining us.',
    'text/html'
);
```

### Queue-Based Sending

[](#queue-based-sending)

```
// Queue for background processing (required env redis vars)
$jobId = $mailer->queue(
    'user@example.com',
    'Welcome to Our App',
    'Welcome!Thanks for joining us.',
    'text/html'
);

echo "Email queued with job ID: $jobId";
```

### Using Mailable Classes

[](#using-mailable-classes)

```
// Generate a new mailable class
php ml make:mail WelcomeMail

// Use the generated class
use App\Mail\WelcomeMail;

$mail = new WelcomeMail();
$mail->setTo('user@example.com')
     ->setViewData(['name' => 'John Doe'])
     ->send(); // or ->queue()
```

---

🎨 Mailable Classes
------------------

[](#-mailable-classes)

Mailable classes provide an elegant, object-oriented way to compose emails with templates, data binding, and fluent configuration.

### Creating a Mailable

[](#creating-a-mailable)

```
# Generate a new mailable class
php ml make:mail OrderConfirmation
```

### Example Mailable Class

[](#example-mailable-class)

```
