Member-only story
How to Use Variables, Tags, and Other Features in Laravel Mailgun Email Sending
3 min readMay 9, 2025
Introduction:
Sending emails through Mailgun with Laravel is easy — but what if you want to personalize your emails using Mailgun variables, track email engagement with tags, or manage campaigns effectively? In this blog, we’ll cover how to integrate advanced Mailgun features with Laravel’s native mail system.
🔧 Prerequisites
Make sure:
- Laravel is installed (
v8+
orv9+
recommended) - You have a Mailgun account
- You’ve verified your domain in Mailgun
📦 Step 1: Install and Configure Mailgun
- Install Guzzle if not already installed
composer require guzzlehttp/guzzle
2. Configure .env
MAIL_MAILER=mailgun
MAILGUN_DOMAIN=yourdomain.com
MAILGUN_SECRET=your-mailgun-private-api-key
MAILGUN_ENDPOINT=api.mailgun.net
3. Configure config/mail.php
'mailers' => [
'mailgun' => [
'transport' => 'mailgun',
],
// other mailers...
],
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'hello@yourdomain.com'),
'name' => env('MAIL_FROM_NAME', 'Your App Name'),
],