Prerequisites: Knowledge of Laravel, Laravel X.X Installation
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
and signup either through your Google account, GitHub account or by providing your email address and password.
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.
To add Mailtrap to your Laravel app, you’ll need to edit your .env file and add the following details
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.
In the resulting page, copy the username and password and add them to your .env file as advised above.
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.
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.