DEV Community

Carlos Santos
Carlos Santos

Posted on

Laravel Mailtrap Setup

Laravel Mailtrap Setup


How will this email look? Will it look nice on mobile? Is the email data correct? You can test all that and more with Mailtrap.

Mailtrap is a testing tool designed to trap any emails coming out of your application. Setting up Mailtrap is a must for your development environment, this way you can test your application functionalities without worrying about spamming real users.

Step 1: Mailtrap Account

  • Go to and sign up.

  • Once you are logged in you will see a menu with 3 options; Inboxes, API, and Billing. Go to Inboxes.

Mailtrap Inboxes

  • On the Inboxes page you will see a list of your inboxes and you will also have the option of creating a new project or creating a new inbox. We will use the default inbox for this setup.

  • Click on the inbox and on SMTP Settings select Integrations -> Laravel.

Mailtrap Inbox Settings

  • Here you will see the .env variables you need to copy.

Mailtrap Laravel Env

Step 2: Laravel Configuration

Add (or replace) mail environment variables from Mailtrap to your application .env file.


# Also
MAIL_FROM_NAME="Mailtrap Test App"

Enter fullscreen mode Exit fullscreen mode

Step 3: Test

Create simple test mailable with markdown.
php artisan make:mail MailtrapTest --markdown=emails.test



namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class MailtrapTest extends Mailable
    use Queueable, SerializesModels;

     * Create a new message instance.
     * @return void
    public function __construct()

     * Build the message.
     * @return $this
    public function build()
        return $this->markdown('emails.test');

Enter fullscreen mode Exit fullscreen mode

resources\views\emails\test.blade.php (Markdown file)


The cake is a lie

{{ config('') }}
Enter fullscreen mode Exit fullscreen mode

Add test route


Route::get('/mailtrap/test', function () {
    // Using a temp email. 
    // This way we can test that emails are really trapped.
    $testEmail = '';

    return Mail::to($testEmail)->send(new MailtrapTest());

Enter fullscreen mode Exit fullscreen mode

Now hit test URL. You should have a new email on your Mailtrap inbox and you should not have any email from your application on the test email inbox.

Mailtrap Inbox


Mailtrap is a very useful tool for development and it's super easy to setup with Laravel. You can find more information at

I hope this article was helpful.

If you have any feedback or found mistakes, please don’t hesitate to reach out to me.

Top comments (0)