PHPackages                             mertcanaydin97/laravel-phpmailer-driver - 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. mertcanaydin97/laravel-phpmailer-driver

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

mertcanaydin97/laravel-phpmailer-driver
=======================================

A custom Laravel mail driver using PHPMailer

1.1.5(9mo ago)023MITPHPPHP &gt;=7.4

Since Aug 5Pushed 9mo agoCompare

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

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

Laravel PHPMailer Driver
========================

[](#laravel-phpmailer-driver)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c1ce2ac73d479165246f7dcdd2a908f2abe2d4799bd64b8297dc4bef3553b8a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d65727463616e617964696e39372f6c61726176656c2d7068706d61696c65722d6472697665722e737667)](https://packagist.org/packages/mertcanaydin97/laravel-phpmailer-driver)[![Total Downloads](https://camo.githubusercontent.com/5477d2c002cff45aea2f2e9e58a82a62168da3a4a02bd0f61c8c9a5d6e7789aa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d65727463616e617964696e39372f6c61726176656c2d7068706d61696c65722d6472697665722e737667)](https://packagist.org/packages/mertcanaydin97/laravel-phpmailer-driver)[![License](https://camo.githubusercontent.com/be2da9a1ec9c776162bb4f9235ebb73d6897bf3efa2c93a6a9c7b150a76a865d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d65727463616e617964696e39372f6c61726176656c2d7068706d61696c65722d6472697665722e737667)](https://github.com/mertcanaydin97/laravel-phpmailer-driver/blob/main/LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/18208846f87d824fea4f3949c8a6d6448c112257607cc96362b4d9cbfb46c680/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d65727463616e617964696e39372f6c61726176656c2d7068706d61696c65722d6472697665722e737667)](https://packagist.org/packages/mertcanaydin97/laravel-phpmailer-driver)

> **❗️ IMPORTANT: This package is optimized for Laravel 10+ with Symfony Mailer. If you see "Mailer \[phpmailer\] not defined", you MUST add the PHPMailer mailer config to your `config/mail.php` (see below) and clear your config cache!**

A powerful and feature-rich Laravel mail driver that seamlessly integrates PHPMailer with Laravel's mail system. This package provides enterprise-grade email functionality with comprehensive attachment support, custom headers, SSL verification options, and extensive debugging capabilities.

✨ Features
----------

[](#-features)

### 🚀 Core Features

[](#-core-features)

- **Custom PHPMailer Integration** - Seamless integration with Laravel's mail system
- **Laravel 10+ Optimized** - Full support for Symfony Mailer with enhanced transport
- **Advanced SMTP Support** - SSL/TLS encryption, authentication, and timeout configuration
- **Rich Email Content** - HTML and plain text email support with automatic fallbacks
- **File Attachments** - Full support for file attachments with proper MIME types
- **Recipient Management** - TO, CC, BCC, and Reply-To support
- **Custom Headers** - Complete custom headers support for tracking and metadata
- **SSL Verification Control** - Configurable SSL certificate verification options

### 🔧 Enhanced Features

[](#-enhanced-features)

- **Type Safety** - Proper type casting and null safety checks
- **Error Handling** - Comprehensive error handling with descriptive messages
- **Fallback Support** - Automatic fallbacks for missing content and addresses
- **Production Ready** - Battle-tested in production environments
- **Clean Architecture** - Well-organized, maintainable code structure

### 🌍 Internationalization

[](#-internationalization)

- **13 Languages Supported** - English, Spanish, French, German, Italian, Portuguese, Russian, Japanese, Chinese, Korean, Arabic, Hindi, Turkish
- **Localized Templates** - All email templates support translation
- **RTL Language Support** - Full support for Arabic and other RTL languages
- **Culture-Specific Formatting** - Date, time, and number formatting

### 📧 Email Templates

[](#-email-templates)

- **6 Beautiful Templates** - Welcome, Password Reset, Notification, Order Confirmation, Contact Form
- **Responsive Design** - Perfect display on desktop, tablet, and mobile
- **Modern Styling** - Beautiful gradients and clean typography
- **Email Client Compatible** - Tested across major email clients
- **Fully Customizable** - Publish and override templates as needed
- **Accessible** - Proper contrast ratios and semantic HTML

### 🛠 Developer Experience

[](#-developer-experience)

- **Artisan Commands** - Built-in testing and utility commands
- **Comprehensive Testing** - Full test suite with PHPUnit
- **Detailed Documentation** - Extensive guides and examples
- **Easy Configuration** - Simple setup and configuration
- **Debug Tools** - Built-in debugging and troubleshooting commands

📋 Requirements
--------------

[](#-requirements)

- PHP 7.4 or higher
- Laravel 9.0, 10.0, 11.0, or newer
- PHPMailer 6.8 or higher

🚀 Quick Installation for Laravel 10+
------------------------------------

[](#-quick-installation-for-laravel-10)

### Step 1: Install the Package

[](#step-1-install-the-package)

```
composer require mertcanaydin97/laravel-phpmailer-driver
```

### Step 2: Configure Mail Settings

[](#step-2-configure-mail-settings)

**CRITICAL**: You MUST add the PHPMailer mailer to your `config/mail.php` file.

1. Open your `config/mail.php` file
2. Find the `mailers` array
3. Add this configuration:

```
'mailers' => [
    // ... existing mailers ...

    // Add this PHPMailer configuration
    'phpmailer' => [
        'transport' => 'phpmailer',
        'host' => env('MAIL_HOST', 'localhost'),
        'port' => env('MAIL_PORT', 587),
        'username' => env('MAIL_USERNAME'),
        'password' => env('MAIL_PASSWORD'),
        'encryption' => env('MAIL_ENCRYPTION', 'tls'),
        'timeout' => env('MAIL_TIMEOUT', 30),
        'debug' => env('MAIL_DEBUG', false),
        'debug_level' => env('MAIL_DEBUG_LEVEL', 0),
        'debug_output' => env('MAIL_DEBUG_OUTPUT', 'error_log'),
        'ssl_verify_peer' => env('MAIL_SSL_VERIFY_PEER', true),
        'ssl_verify_peer_name' => env('MAIL_SSL_VERIFY_PEER_NAME', true),
        'ssl_allow_self_signed' => env('MAIL_SSL_ALLOW_SELF_SIGNED', false),
    ],
],
```

**See `examples/config-mail.php` for a complete example.**

### Step 3: Set Environment Variables

[](#step-3-set-environment-variables)

Add these to your `.env` file:

```
MAIL_MAILER=phpmailer
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-email@gmail.com
MAIL_PASSWORD=your-app-password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=your-email@gmail.com
MAIL_FROM_NAME="${APP_NAME}"
MAIL_TIMEOUT=30
MAIL_DEBUG=false
MAIL_DEBUG_LEVEL=0
MAIL_DEBUG_OUTPUT=error_log
MAIL_SSL_VERIFY_PEER=true
MAIL_SSL_VERIFY_PEER_NAME=true
MAIL_SSL_ALLOW_SELF_SIGNED=false
```

### Step 4: Clear All Caches

[](#step-4-clear-all-caches)

```
php artisan config:clear
php artisan cache:clear
composer dump-autoload
```

### Step 5: Test the Installation

[](#step-5-test-the-installation)

```
php artisan phpmailer:test
```

📖 Usage
-------

[](#-usage)

### Basic Email Sending

[](#basic-email-sending)

```
use Illuminate\Support\Facades\Mail;

// Simple text email
Mail::mailer('phpmailer')->raw('Hello World', function ($message) {
    $message->to('user@example.com')
            ->subject('Test Email');
});

// HTML email
Mail::mailer('phpmailer')->html('Hello World', function ($message) {
    $message->to('user@example.com')
            ->subject('Test HTML Email');
});
```

### Advanced Email Features

[](#advanced-email-features)

```
// Multiple recipients with CC, BCC, and Reply-To
Mail::mailer('phpmailer')->raw('Hello World', function ($message) {
    $message->to(['user1@example.com', 'user2@example.com'])
            ->cc('cc@example.com')
            ->bcc('bcc@example.com')
            ->replyTo('reply@example.com', 'Reply Name')
            ->subject('Test Email');
});

// With attachments
Mail::mailer('phpmailer')->raw('Hello World', function ($message) {
    $message->to('user@example.com')
            ->subject('Test Email')
            ->attach('/path/to/file.pdf')
            ->attach('/path/to/image.jpg');
});

// With custom headers
Mail::mailer('phpmailer')->raw('Hello World', function ($message) {
    $message->to('user@example.com')
            ->subject('Test Email')
            ->getHeaders()
            ->addTextHeader('X-Custom-Header', 'Custom Value')
            ->addTextHeader('X-Priority', '1');
});
```

### Using Mailable Classes

[](#using-mailable-classes)

```
use Illuminate\Mail\Mailable;

class WelcomeEmail extends Mailable
{
    public function build()
    {
        return $this->view('emails.welcome')
                    ->subject('Welcome to Our App')
                    ->attach('/path/to/welcome.pdf');
    }
}

// Send using PHPMailer
Mail::mailer('phpmailer')->to('user@example.com')->send(new WelcomeEmail());
```

🔧 Configuration Options
-----------------------

[](#-configuration-options)

### Environment Variables

[](#environment-variables)

VariableDescriptionDefaultConfig Key`MAIL_MAILER`Mail driver to use`phpmailer`-`MAIL_HOST`SMTP host`localhost``host``MAIL_PORT`SMTP port`587``port``MAIL_USERNAME`SMTP username-`username``MAIL_PASSWORD`SMTP password-`password``MAIL_ENCRYPTION`Encryption type (`tls` or `ssl`)`tls``encryption``MAIL_FROM_ADDRESS`Default from address-`from_address``MAIL_FROM_NAME`Default from name-`from_name``MAIL_TIMEOUT`SMTP timeout in seconds`30``timeout``MAIL_DEBUG`Enable SMTP debugging`false``debug``MAIL_DEBUG_LEVEL`Debug level (0-4)`0``debug_level``MAIL_DEBUG_OUTPUT`Debug output method`error_log``debug_output``MAIL_SSL_VERIFY_PEER`Verify SSL peer certificate`true``ssl_verify_peer``MAIL_SSL_VERIFY_PEER_NAME`Verify SSL peer name`true``ssl_verify_peer_name``MAIL_SSL_ALLOW_SELF_SIGNED`Allow self-signed certificates`false``ssl_allow_self_signed`### Configuration File

[](#configuration-file)

The package uses `config/phpmailer.php` for configuration. You can publish this file using:

```
php artisan vendor:publish --provider="Mertcanaydin97\LaravelPhpMailerDriver\PhpMailerServiceProvider" --tag=phpmailer-config
```

**Configuration Structure:**

```
