PHPackages                             ankitfromindia/mx18-laravel - 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. ankitfromindia/mx18-laravel

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

ankitfromindia/mx18-laravel
===========================

Laravel package for MX18 Email API integration - send single/bulk emails and handle webhooks

2.1.0(4mo ago)07MITPHPPHP ^8.3

Since Dec 16Pushed 4mo agoCompare

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

READMEChangelogDependencies (4)Versions (7)Used By (0)

MX18 Laravel Package
====================

[](#mx18-laravel-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/179c2d5ed15c24cd2a0fa718bea7cf27bdfe4a55afda6d47bf98943113a72a6c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616e6b697466726f6d696e6469612f6d7831382d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ankitfromindia/mx18-laravel)[![Total Downloads](https://camo.githubusercontent.com/c8dbf5647cdddfbaf9f232590be16387a8dfdf9a74e909bf525873e648fd4c33/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616e6b697466726f6d696e6469612f6d7831382d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ankitfromindia/mx18-laravel)

Laravel package for [MX18](https://mx18.com) Email API integration. Send single/bulk emails and handle webhooks with ease.

Version 2.1.0 - New Feature
---------------------------

[](#version-210---new-feature)

🚀 **New Features:**

- ✅ `addRecipient()` method for efficient bulk emails
- ✅ Multiple recipients with individual personalization in single API call

Version 2.0.0 - Major Release
-----------------------------

[](#version-200---major-release)

🚀 **New Features:**

- ✅ Custom headers support
- ✅ Custom arguments for tracking
- ✅ Full MX18 API v1 compatibility

⚠️ **Breaking Changes:**

- Authentication changed from `Bearer` token to `X-Api-Key` header
- See [Migration Guide](#migration-from-v1x) below

Features
--------

[](#features)

- ✅ Send single emails
- ✅ Send bulk emails
- ✅ Handle webhooks with signature verification
- ✅ Support for HTML/text content
- ✅ File attachments
- ✅ Email personalization
- ✅ CC/BCC recipients
- ✅ Custom headers
- ✅ Custom arguments
- ✅ Laravel auto-discovery

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 10.0+, 11.0+, or 12.0+
- MX18 account with API token

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

[](#installation)

```
composer require ankitfromindia/mx18-laravel
```

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

[](#configuration)

### 1. Publish Config

[](#1-publish-config)

```
php artisan vendor:publish --tag=mx18-config
```

### 2. Environment Variables

[](#2-environment-variables)

Add to your `.env`:

```
MX18_API_TOKEN=your_api_token_here
MX18_WEBHOOK_SECRET=your_webhook_secret_optional
MX18_WEBHOOK_PATH=/mx18/webhook
```

### 3. Get API Token

[](#3-get-api-token)

1. Sign up at [MX18](https://mx18.com)
2. Get your API token from [Account Settings](https://app.mx18.com/account-settings)
3. Verify your sender domain

Usage
-----

[](#usage)

### Basic Email

[](#basic-email)

```
use AnkitFromIndia\MX18\Mail\MX18Mail;
use AnkitFromIndia\MX18\Facades\MX18;

$mail = (new MX18Mail())
    ->from('sender@yourdomain.com', 'Your Name')
    ->to('recipient@example.com', 'Recipient Name')
    ->subject('Welcome to Our Service')
    ->html('Hello {{name}}!Welcome to our platform.')
    ->text('Hello {{name}}! Welcome to our platform.');

$response = MX18::send($mail);
```

### Advanced Email with Personalization

[](#advanced-email-with-personalization)

```
$mail = (new MX18Mail())
    ->from('noreply@yourdomain.com', 'Your Company')
    ->to('user@example.com', 'John Doe', ['name' => 'John', 'plan' => 'Premium'])
    ->cc('manager@yourdomain.com', 'Manager')
    ->replyTo('support@yourdomain.com', 'Support Team')
    ->subject('Your {{plan}} account is ready!')
    ->html('Hi {{name}}Your {{plan}} plan is now active.')
    ->globalPersonalization(['company' => 'Your Company']);

$response = MX18::send($mail);
```

### File Attachments

[](#file-attachments)

```
$pdfContent = base64_encode(file_get_contents('/path/to/file.pdf'));

$mail = (new MX18Mail())
    ->from('sender@yourdomain.com')
    ->to('recipient@example.com')
    ->subject('Invoice Attached')
    ->html('Please find your invoice attached.')
    ->attach($pdfContent, 'invoice.pdf', 'application/pdf');

$response = MX18::send($mail);
```

### Custom Headers and Arguments

[](#custom-headers-and-arguments)

```
$mail = (new MX18Mail())
    ->from('sender@yourdomain.com')
    ->to('recipient@example.com')
    ->subject('Email with Custom Headers')
    ->html('Email content')
    ->headers([
        'X-Custom-Header' => 'CustomValue',
        'X-Mailer' => 'MX18 API'
    ])
    ->customArguments([
        'customerAccountNumber' => '12345',
        'campaignId' => 'summer2024'
    ]);

$response = MX18::send($mail);
```

### Efficient Bulk Email (New in v2.1.0)

[](#efficient-bulk-email-new-in-v210)

```
$mail = (new MX18Mail())
    ->from('newsletter@yourdomain.com', 'Your Company')
    ->addRecipient('user1@example.com', 'John', ['name' => 'John', 'plan' => 'Premium'])
    ->addRecipient('user2@example.com', 'Jane', ['name' => 'Jane', 'plan' => 'Basic'])
    ->subject('Welcome {{name}}!')
    ->html('Hi {{name}}Your {{plan}} plan is ready.');

$response = MX18::send($mail);
```

### Bulk Email

[](#bulk-email)

```
$mails = [
    (new MX18Mail())
        ->from('newsletter@yourdomain.com')
        ->to('user1@example.com', 'User One')
        ->subject('Newsletter #1')
        ->html('Newsletter Content'),

    (new MX18Mail())
        ->from('newsletter@yourdomain.com')
        ->to('user2@example.com', 'User Two')
        ->subject('Newsletter #2')
        ->html('Different Content'),
];

$responses = MX18::sendBulk($mails);

foreach ($responses as $response) {
    echo "Transaction ID: " . $response['transactionId'] . "\n";
}
```

Webhooks
--------

[](#webhooks)

### 1. Setup Webhook URL

[](#1-setup-webhook-url)

Get your webhook URL:

```
$webhookUrl = MX18::getWebhookUrl();
// Returns: https://yourdomain.com/mx18/webhook
```

Configure this URL in your [MX18 Dashboard](https://app.mx18.com) under Webhooks settings.

### 2. Handle Webhook Events

[](#2-handle-webhook-events)

Create an event listener:

```
// In EventServiceProvider.php
use AnkitFromIndia\MX18\Webhooks\WebhookReceived;

protected $listen = [
    WebhookReceived::class => [
        'App\Listeners\HandleMX18Webhook',
    ],
];
```

Create the listener:

```
// app/Listeners/HandleMX18Webhook.php
