Email Templates
Learn how to create, customize, and manage email templates in LaraDashboard for transactional and marketing communications.
Email Templates
LaraDashboard provides a powerful email template system for creating beautiful transactional and marketing emails with a visual builder or code editor.
Overview
Email Template Features
- Visual Builder - Drag-and-drop email design
- Code Editor - Full HTML/Blade access
- Variables - Dynamic content placeholders
- Preview - Real-time preview across devices
- Testing - Send test emails instantly
- Versioning - Track template changes
Template Types
| Type | Purpose | Examples |
|---|---|---|
| System | Automated notifications | Welcome, Password Reset |
| Transactional | User-triggered emails | Order Confirmation |
| Marketing | Promotional content | Newsletters, Campaigns |
| Custom | Module-specific | CRM, Custom workflows |
Managing Templates
Accessing Templates
Navigate to Settings → Email → Templates
Template List
┌─────────────────────────────────────────────────────────────────┐
│ Email Templates [+ New Template] [Search] │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Name Type Status Last Modified │
│ ───────────────────────────────────────────────────────────── │
│ Welcome Email System Active Jan 15, 2024 │
│ Password Reset System Active Jan 10, 2024 │
│ Email Verification System Active Jan 8, 2024 │
│ Newsletter Marketing Draft Jan 12, 2024 │
│ Order Confirmation Transaction Active Jan 14, 2024 │
│ │
└─────────────────────────────────────────────────────────────────┘
Creating Templates
Create New Template
- Click + New Template
- Enter template details:
Name: Order Confirmation
Slug: order-confirmation (auto-generated)
Type: Transactional
Subject: Your Order #{{order_number}} is Confirmed
- Choose editor type:
- Visual Builder - Drag-and-drop design
- Code Editor - HTML/Blade code
Visual Builder
The visual email builder provides:
┌─────────────────┬───────────────────────────────────────────────┐
│ │ │
│ Block Library │ Email Canvas │
│ │ │
│ ├── Header │ ┌─────────────────────────────────────┐ │
│ ├── Content │ │ [LOGO] │ │
│ ├── Image │ │ Your Order is Confirmed! │ │
│ ├── Button │ │ │ │
│ ├── Divider │ │ Order #{{order_number}} │ │
│ ├── Columns │ │ Date: {{order_date}} │ │
│ └── Footer │ │ │ │
│ │ │ [View Order Button] │ │
│ │ │ │ │
│ │ │ Thanks for your purchase! │ │
│ │ └─────────────────────────────────────┘ │
│ │ │
└─────────────────┴───────────────────────────────────────────────┘
Available Blocks
| Block | Description |
|---|---|
| Header | Logo and navigation |
| Hero | Large headline section |
| Text | Rich text content |
| Image | Single image |
| Button | Call-to-action button |
| Columns | Multi-column layout |
| Divider | Horizontal separator |
| Spacer | Vertical spacing |
| Social | Social media links |
| Footer | Footer with unsubscribe |
Code Editor
For advanced customization:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>{{ $subject }}</title>
</head>
<body>
<div style="max-width: 600px; margin: 0 auto;">
<h1>Welcome, {{ $user->name }}!</h1>
<p>Thank you for joining {{ config('app.name') }}.</p>
<a href="{{ $verificationUrl }}"
style="background: #6366f1; color: white; padding: 12px 24px;">
Verify Email
</a>
<p>If you didn't create this account, please ignore this email.</p>
</div>
</body>
</html>
Template Variables
System Variables
Available in all templates:
| Variable | Description |
|---|---|
{{app_name}} |
Application name |
{{app_url}} |
Application URL |
{{current_year}} |
Current year |
{{support_email}} |
Support email address |
User Variables
Available when user context exists:
| Variable | Description |
|---|---|
{{user.name}} |
User's full name |
{{user.first_name}} |
First name |
{{user.last_name}} |
Last name |
{{user.email}} |
Email address |
Custom Variables
Define template-specific variables:
// In your notification or mail class
public function toMail($notifiable)
{
return (new MailMessage)
->template('order-confirmation')
->with([
'order_number' => $this->order->number,
'order_total' => $this->order->formatted_total,
'order_items' => $this->order->items,
]);
}
Use in template:
<p>Order #{{ $order_number }}</p>
<p>Total: {{ $order_total }}</p>
@foreach($order_items as $item)
<p>{{ $item->name }} - {{ $item->price }}</p>
@endforeach
Styling Emails
Inline Styles
Email clients require inline styles:
<p style="color: #333333; font-size: 16px; line-height: 1.5;">
Your content here
</p>
CSS Classes (Builder)
The visual builder handles inline conversion automatically:
<!-- Builder generates -->
<p class="text-body">Your content</p>
<!-- Converted to -->
<p style="color: #333333; font-size: 16px; line-height: 1.5;">
Your content here
</p>
Responsive Design
Templates are mobile-responsive by default:
<style>
@media screen and (max-width: 600px) {
.container {
width: 100% !important;
}
.column {
display: block !important;
width: 100% !important;
}
}
</style>
System Templates
Default System Templates
| Template | Trigger | Variables |
|---|---|---|
| Welcome | User registration | user, login_url |
| Password Reset | Reset request | user, reset_url, expiry |
| Email Verification | New registration | user, verification_url |
| Password Changed | Password update | user |
Customizing System Templates
- Navigate to the template
- Click Edit
- Customize design and content
- Keep required variables intact
- Save changes
Important: Don't remove required variables like
{{reset_url}}from system templates.
Testing Templates
Preview Mode
- Open template editor
- Click Preview
- Toggle between desktop/mobile views
- Check all devices
Send Test Email
- Click Send Test
- Enter recipient email
- Optionally fill test variables
- Click Send
- Check inbox
Test Data
Provide sample data for testing:
{
"user": {
"name": "John Doe",
"email": "john@example.com"
},
"order_number": "ORD-12345",
"order_total": "$99.99"
}
Email Connections
Setting Default Connection
- Go to Settings → Email → Connections
- Click Set as Default on preferred connection
- All emails use this connection unless specified
Per-Template Connection
Override default for specific templates:
// In template settings or code
$this->connection = 'marketing-mailgun';
Fallback Configuration
If primary fails, use fallback:
// config/mail.php
'default' => env('MAIL_MAILER', 'smtp'),
'fallback' => env('MAIL_FALLBACK', 'log'),
Email Logs
Viewing Logs
Navigate to Settings → Email → Logs
┌─────────────────────────────────────────────────────────────────┐
│ Email Logs [Filter] [Search]│
├─────────────────────────────────────────────────────────────────┤
│ │
│ To Subject Status Sent At │
│ ───────────────────────────────────────────────────────────── │
│ user@email.com Welcome Email ✓ Sent Jan 15, 10:30 AM │
│ test@test.com Password Reset ✓ Sent Jan 15, 10:25 AM │
│ john@doe.com Order Confirm ✗ Failed Jan 15, 10:20 AM │
│ │
└─────────────────────────────────────────────────────────────────┘
Log Details
Click on a log entry to see:
- Full email content
- Headers
- Error message (if failed)
- Retry option
Retrying Failed Emails
- Open failed email log
- Review error message
- Fix issue (e.g., invalid email)
- Click Retry
Best Practices
Design Guidelines
-
Keep it Simple
- Single column layouts work best
- Clear hierarchy with headings
- Minimal images for faster loading
-
Mobile First
- Test on mobile devices
- Use large tap targets (44px minimum)
- Readable font sizes (14px minimum)
-
Consistent Branding
- Use brand colors
- Include logo
- Maintain voice and tone
Content Tips
-
Subject Lines
- Keep under 50 characters
- Personalize when possible
- Create urgency or curiosity
-
Body Content
- Lead with most important info
- Use short paragraphs
- Include clear CTA
-
Call to Action
- Single primary CTA per email
- Button text: action-oriented
- High contrast colors
Deliverability
-
Authentication
- Set up SPF records
- Configure DKIM
- Enable DMARC
-
List Hygiene
- Include unsubscribe link
- Honor opt-outs promptly
- Remove bounced addresses
-
Content Quality
- Avoid spam trigger words
- Balance text to image ratio
- Test with spam checkers
Template API
Creating Templates Programmatically
use App\Models\EmailTemplate;
$template = EmailTemplate::create([
'name' => 'Welcome Email',
'slug' => 'welcome-email',
'type' => 'system',
'subject' => 'Welcome to {{app_name}}',
'content' => '<html>...</html>',
'design' => [...], // Builder JSON
'is_active' => true,
]);
Using Templates in Code
use App\Mail\TemplateMail;
Mail::to($user)->send(
new TemplateMail('welcome-email', [
'user' => $user,
'login_url' => route('login'),
])
);
Template Events
Hook into template events:
// In EventServiceProvider
EmailTemplate::created(function ($template) {
Log::info("Template created: {$template->name}");
});
EmailTemplate::updated(function ($template) {
Cache::forget("email-template.{$template->slug}");
});
Troubleshooting
Email Not Sending
- Check email connection settings
- Verify credentials
- Test with simple SMTP
- Check server allows outbound SMTP
- Review email logs for errors
Template Not Rendering
- Check for Blade syntax errors
- Verify all variables are passed
- Clear view cache:
php artisan view:clear
Images Not Displaying
- Use absolute URLs for images
- Host images on accessible server
- Check image file size (under 1MB)
- Verify URL is not blocked
Styling Issues
- Use inline styles
- Test across email clients
- Avoid CSS3 features
- Use tables for layout (legacy clients)
Next Steps
- Settings - Configure email connections
- Notification System - Advanced notifications
- Email Providers - Provider configuration