Setting up Mailtrap for Laravel Development

Christian Jombo
Feb 6 · 3 min read

Prerequisites: Knowledge of Laravel, Laravel X.X Installation
Difficulty: Beginner

One of the major challenges in development is email testing on local development environments. This is why Mailtrap.io is a very essential service.

Mailtrap is a fake SMTP server to test, view and share emails sent from the development and staging environments. It allows you to test email notifications without sending them to the real users of the application. It also lets you view all your emails online, forward them to your regular mailbox, share with the team and more! All emails sent to Mailtrap are held in your Mailtrap inbox where you can test, view and share with your team.

To create an account, visit https://mailtrap.io

Mailtrap provides a fake SMTP server to test emails sent from development environments

and signup either through your Google account, GitHub account or by providing your email address and password.

Signup for a mailtrap account using your Google, Github or email account

Once logged in, you’ll have to create an inbox. After creating the inbox, you’ll get the inbox email address to which you can send all your notification emails. The email address will usually look like ‘anyString@inbox.mailtrap.io’. I’m logged in using my GitHub account and my dashboard looks like this.

Mailtrap dashboard

To add Mailtrap to your Laravel app, you’ll need to edit your .env file and add the following details

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=yourMailtrapUsername
MAIL_PASSWORD=yourMailtrapPassword
MAIL_ENCRYPTION=tls

Replace ‘yourMailtrapUsername’ and ‘yourMailtrapPassword’ with your Mailtrap username and password respectively. You can get your Mailtrap username and password by clicking on the gear icon (settings) which is beside your Mailtrap inbox.

Gear icon is indicated with the arrow and circle

In the resulting page, copy the username and password and add them to your .env file as advised above.

Copy out the username and password for addition to your .env file

Save your .env file and send an email from your application. If you’ve followed the steps correctly, your email should appear in your Mailtrap inbox. Congratulations, you now have a fake SMTP server to test emails sent from your application.

Thanks for reading. Hope this helps.

Follow me on Twitter
Add me on LinkedIn

If you want to customize the default notification email template, check out this awesome article by yours truly and don’t forget to clap if you find it useful.

Christian Jombo

Written by

Passionate about building amazing solutions for social and business problems using technology

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade