P H O T O N

CONSOLE

Loading

Laravel 10 & 11 Framework Guide

How to Configure External SMTP Relay in Laravel 10 & 11
Production .env Setup • Queue Workers • Failover Config

Integrate high-speed authenticated SMTP into Laravel in under 2 minutes. Eliminate checkout lag with asynchronous queue workers and achieve sub-700ms OTP delivery.

5 min read • Laravel 10 & 11 Tested • Production Snippets
Direct Answer: Configuring SMTP in Laravel

In Laravel 10 and 11, configure an external SMTP relay by updating your .env file with MAIL_MAILER=smtp, MAIL_HOST=mail.photonrelay.com, MAIL_PORT=587, MAIL_ENCRYPTION=tls, and your authenticated API credentials. For production high-throughput, dispatch emails through queued Mailable classes using implements ShouldQueue.

1. Production .env SMTP Settings

Add the following configuration directives to your Laravel root .env file:

MAIL_MAILER=smtp
MAIL_HOST=mail.photonrelay.com
MAIL_PORT=587
MAIL_USERNAME=your_photon_api_key
MAIL_PASSWORD=your_photon_api_secret
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="notifications@yourdomain.com"
MAIL_FROM_NAME="${APP_NAME}"
MAIL_TIMEOUT=15

After editing, clear your cached configuration:

php artisan config:clear
php artisan config:cache

2. Failover Configuration in config/mail.php

Laravel allows you to configure multi-mailer failover groups. If the primary connection experiences a timeout, Symfony Mailer automatically routes to the secondary mailer:

// config/mail.php
'mailers' => [
  'failover' => [
    'transport' => 'failover',
    'mailers' => [
      'photonrelay',
      'ses',
    ],
  ],
  'photonrelay' => [
    'transport' => 'smtp',
    'host' => env('MAIL_HOST', 'mail.photonrelay.com'),
    'port' => env('MAIL_PORT', 587),
    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME'),
    'password' => env('MAIL_PASSWORD'),
  ],
],

3. Asynchronous Queue Workers for Sub-Second Checkout

Never send transactional emails synchronously during an HTTP request. Implement the ShouldQueue interface on your Mailable class:

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class OrderReceiptMail extends Mailable implements ShouldQueue
{
  use Queueable, SerializesModels;
  // ...
}

4. Testing Delivery with Artisan Tinker

Verify connectivity directly from the terminal without building a test route:

php artisan tinker

# Execute inside Tinker:
Mail::raw('Testing PhotonRelay delivery in Laravel', function ($m) {
  $m->to('your-email@example.com')->subject('Laravel SMTP Test');
});

Send Sub-Second Emails in Laravel with PhotonRelay

Enjoy 5,000 free transactional emails every month. Scale at a flat $0.50 per 1,000 with dedicated Anycast edge acceleration.

5. Frequently Asked Questions

The synchronous mail driver forces the user's web request to wait until the remote SMTP socket connects and completes TLS negotiation (typically 300 to 1,500ms). In production, dispatch emails via background queue workers using 'php artisan queue:work' to make response times instantaneous.

PhotonRelay uses globally trusted certificates from Let's Encrypt and DigiCert. Ensure your php.ini has 'openssl.cafile' pointing to an updated cacert.pem bundle, and set MAIL_ENCRYPTION=tls on Port 587 in your .env file.

Yes. In Laravel config/mail.php, configure a 'failover' transport that attempts delivery through PhotonRelay first, falling back to a secondary mailer if network connectivity fails.