Last Updated: September 01, 2020
· oliverusselldev

Laravel Mailtrap Integration

Here is how you can integrate Laravel and Mailtrap. Paste following in .env

MAIL_USERNAME= //your username generated by Mailtrap
MAIL_PASSWORD= // your password generated by Mailtrap

create a Mailable class

php artisan make:mail MailtrapExample

Modify the mailtrap template with following code

namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class MailtrapExample 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->from('', 'Mailtrap')
            ->subject('Mailtrap Confirmation')
                'name' => 'New Mailtrap User',
                'link' => ''

Create a route

use App\Mail\MailtrapExample;
use Illuminate\Support\Facades\Mail;
Route::get('/send-mail', function () {
    Mail::to('')->send(new MailtrapExample()); 
    return 'A message has been sent to Mailtrap!';

Source: Laravel Mailtrap integration