Use Mailgun SMTP in a Laravel App

Mailgun is a service for sending transnational emails from your app. Once you’ve created your Mailgun account and verified it with your app’s domain, here are the steps for making your app use Mailgun’s SMTP service for sending emails from the app.

1. Edit the .env file on the production server.

I use Forge, so I go to my site on the dashboard at forge.laravel.com, click on Environment and edit the environment.
For the mail settings, I use the following:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=2525
MAIL_USERNAME=postmaster@mg.mydomain.com
MAIL_PASSWORD=myfancypasswordfrommailgunhere
MAIL_ENCRYPTION=null

2. Update the default “from” settings to match my app.

In the .env file, I add the following:

MAIL_FROM_ADDRESS=info@mydomain.com
MAIL_FROM_NAME=MyAppName

That’s it! Now my app is using Mailgun’s SMTP service to send emails from the app.

Leave a Reply

%d bloggers like this: