Email Notifications
Laratic includes several email notifications that are automatically sent to users and administrators. This page lists all available notifications and how they work.
Setting Up Your Email Service
Before sending email notifications, you need to configure an email service. This application supports multiple email providers. For development and testing, we recommend using Mailtrap. For production, use Mailgun.
1. Setting Up Mailtrap for Testing
Mailtrap is a fake SMTP server that captures all emails sent by your application during development. This allows you to test email functionality without sending real emails to users.
Steps to configure Mailtrap:
- Sign up for a free account at mailtrap.io
- Create a new inbox in your Mailtrap dashboard
- Navigate to the inbox integrations and copy your SMTP credentials, you can find Laravel specific code in the "Code Samples" section.
- Add the following environment variables to your
.envfile:
MAIL_MAILER=smtp
MAIL_HOST=sandbox.smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your_mailtrap_username
MAIL_PASSWORD=your_mailtrap_password
Replace your_mailtrap_username and your_mailtrap_password with your actual Mailtrap
credentials.
After configuring these settings, all emails sent by your application will be captured in your Mailtrap inbox, allowing you to preview them without sending real emails.
2. Setting Up Mailgun for Production
Mailgun is a transactional email service that delivers emails reliably in production. It's configured as the default mailer in this application.
Steps to configure Mailgun:
- Sign up for an account at mailgun.com
- Verify your domain in the Mailgun dashboard (or use the sandbox domain for testing)
- Navigate to your domain settings and copy your API credentials
- Add the following environment variables to your
.envfile:
MAILGUN_DOMAIN=your_mailgun_domain
MAILGUN_SECRET=your_mailgun_secret_key
MAILGUN_ENDPOINT=api.mailgun.net
MAIL_FROM_ADDRESS=noreply@yourdomain.com
MAIL_FROM_NAME="Your App Name"
# This is the email address that will receive the contact requests
CONTACT_EMAIL=your@contact.email
Replace the following values:
your_mailgun_domain- Your verified Mailgun domain (e.g.,mg.yourdomain.comor the sandbox domain)your_mailgun_secret_key- Your Mailgun API secret key (found in your Mailgun dashboard under "API Keys")noreply@yourdomain.com- The email address you want to send from (must be from your verified domain)
Please refer to the Laravel's Mailgun documentation for more information.
Once configured, your application will use Mailgun to send all email notifications in production. Make sure to verify your domain in Mailgun to ensure proper deliverability.
Available Notifications
Welcome Notification
Sent automatically when a new user registers. This notification welcomes the user and provides a link to the dashboard.
Class: App\Notifications\WelcomeNotification
When it's sent: Automatically triggered by the Registered event listener when a
user registers.
Template: resources/views/emails/welcome.blade.php
Email Verification Notification
Sent when a user requests an email verification code for two-factor authentication.
Class: App\Notifications\EmailVerificationNotification
When it's sent: When a user requests email verification for 2FA.
Usage:
$user->notify(new EmailVerificationNotification($code));
Order Paid Notification
Sent to the customer when their order payment is successfully processed.
Class: App\Notifications\OrderPaidNotification
When it's sent: Automatically when a Paddle transaction is completed and the order is marked as paid.
Template: resources/views/emails/order-paid.blade.php
Usage:
$user->notify(new OrderPaidNotification($order));
Order Paid Admin Notification
Sent to all admin users when an order payment is successfully processed.
Class: App\Notifications\OrderPaidAdminNotification
When it's sent: Automatically when a Paddle transaction is completed and the order is marked as paid.
Template: resources/views/emails/order-paid-admin.blade.php
Usage:
$admin->notify(new OrderPaidAdminNotification($order));
How to Send Notifications
All notifications can be sent using Laravel's notification system. The most common way is to use the
notify() method on a user model:
use App\Notifications\WelcomeNotification;
$user->notify(new WelcomeNotification);
Email Templates
All email notifications use Laravel's markdown mail components. Templates are located in
resources/views/emails/ and use the <x-mail::message> component for consistent
styling.
To customize an email template, edit the corresponding Blade file in resources/views/emails/.
Automatic Notifications
Some notifications are sent automatically through event listeners:
- Welcome Notification: Sent via
App\Listeners\SendWelcomeNotificationwhen theRegisteredevent fires. - Order Paid Notifications: Sent in
handle_paddle_transaction_completed()when a Paddle webhook processes a payment.