Laravel is an extraordinarily popular PHP framework for building powerful web applications. With a thriving community, Laravel enables pretty much any concept you can think of - including email. In this post we'll show you how to setup a basic Laravel application with Composer and enable email functionality. We will use two methods to send and read email in our app: SMTP connections and an email API provider.
See also our Mailable and Notification Laravel guide
Concept
To demonstrate email sending we will create a Laravel webapp with a view that provides a button that will send an email from one address to another. We will then use a second button to display the sent email. This will give us a good example of how to read and compose emails in PHP.
Getting starting
Let's get up and running by creating a new Laravel project. First verify you have PHP installed by opening a terminal and running
php -v
PHP command not found?
If you see that php command is not found then you need to install PHP on your machine. On a Mac this can be done with Homebrew.
brew install php
Install Composer package manager
The next step is to install the PHP package manager composer.

Download the composer installation script from the downloads page:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '55ce33d7678c5a611085589f1f3ddf8b3c52d662cd01d4ba75c0ee0459970c2200a51f492d557530c71c15d8dba01eae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Then use PHP to run the setup script:
php composer-setup.php --install-dir=bin --filename=composer
This will create a local file called composer. We can install the executable globally by moving it to the user path.
mv composer.phar /usr/local/bin/composer
Create new Laravel app
Now we can use composer to create a new Laravel application:
composer create-project laravel/laravel php-laravel-email-examples
This command will create a new directory called php-laravel-email-examples with a directory structure like so:
% tree -L 1
.
├── README.md
├── app
├── artisan
├── bootstrap
├── composer.json
├── composer.lock
├── config
├── database
├── lang
├── package.json
├── phpunit.xml
├── public
├── resources
├── routes
├── storage
├── tests
├── vendor
└── vite.config.js
Verify the app works
We can check that our new app works correctly by running the generated unit tests with the artisan test command:
% php artisan test
PASS Tests\Unit\ExampleTest
✓ that true is true
PASS Tests\Feature\ExampleTest
✓ the application returns a successful response
Tests: 2 passed
Time: 0.04s
Run the webserver
We can also run the webserver and view the webapp in a browser using artisan:
php artisan serve
This will start a server on localhost:8000 by default.

Creating a dummy view
Now that we have an application let us modify the default view page served by the index to include two buttons, one for sending one for receiving emails. Views are found in the resources/views directory. Open the routes/web.php file to view the current route setup:
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Notice the use of a welcome template view. This refers to the welcome view inside the views directory:
resources/views/welcome.blade.php
We can replace this route with our own called index:
Route::get('/', function () {
return view('index');
});
Then create a new template in the views directory called index.blade.php.
Setting up the mail server
Now we have a basic application we can configure email sending using either a .env or mail.php settings. We can then use the mail server with either Laravel Mailable or Notifications to send emails. Later we'll show you how to receive email too!
Create a mail server account
You need access to an SMTP server for the next steps. Luckily MailSlurp provides free mail servers than can be integrated into any Laravel app! Just sign up for a free account and copy the API Key and SMTP details from the dashboard.

Create a .env file
If you plan to use a single mail server you can configure a .env file in your project root like this:
MAIL_MAILER=smtp
MAIL_HOST=mailslurp.mx
MAIL_PORT=2587
MAIL_USERNAME=your-smtp-username
MAIL_PASSWORD=your-smtp-password
MAIL_FROM_ADDRESS="your-inbox@mailslurp.com"
Configuring mail.php
If you want to provision inboxes dynamically use the MailSlurp PHP library instead. We can configure the mail settings in config/mail.php like this:
Now run this command to load the config changes:
php artisan config:cache
Sending email
To send email in Laravel we have a number of options: direct SMTP with PHPMailer, Notifications, and Mailable interface. Let's cover those now.
Sending directly with SMTP
To directly send an email with can use the SMTP mailserver details and PHPMailer to send an email:
Sending with Laravel Mailable
First create a new mail object using artisan:
php artisan make:mail Newsletter
Then define our views for the mail:
We wrote emails.newsletter for the content view, we also define a blade template resources/views/emails/newsletter:
This template becomes the email body when sending.
Sending with Laravel notifications
Laravel also supports multi-channel notifications (meaning we could also send SMS for example). Let us define a new Notification:
php artisan make:notification NewsletterNotification
Inside the class we define our content:
Note that we haven't specified a view because laravel add notification styles for us. This is a big difference in Notifications and Mailables.
Receive email
To receive email in Laravel or PHP we can use the MailSlurp SDK to fetch emails from our mail server over HTTP/S or configure a webhook that will POST emails to our server.
Polling for emails
Using webhooks
Webhooks allow you to handle emails on your server without requesting them directly. You create webhook in MailSlurp that is triggered for any new inboxes. This webhook the sends the email to your server via HTTP/S POST.
Laravel email rollout checklist
When moving this example from local setup to production:
- Validate SMTP and API behavior in Email Sandbox.
- Add deterministic assertions with Email Integration Testing.
- Handle inbound events with Email Webhooks.
- Route retries and parsing through Email Automation Routing.
- Use the Inbound Email API for webhook vs polling architecture decisions.
- Run pre-release checks with an Email Deliverability Test.



