Mailgun and Laravel 5

Introduction

Mailgun is a very popular API that allows you to send emails directly from the website. We used it in a product lottery, which we have been preparing recently for one of our foreign clients. One of its key advantages is the ability to track e-mails, we can thus collect much more accurate data on user behavior. Sending messages by this method in comparison with, for example, popular SMTP mailing significantly reduces the chance that the message will fall into SPAM or be rejected by the client’s server.

In this post I am going to introduce you how you can easily configure Laravela to work with Mailgun.

Configuration

First, we need to enter new data into our .env configuration file.

If you have not created your account on MailGun.com so far, this is the last moment to do it. The second step is adding the domain and secret key available in our MailGun administration panel.

Once you have all the information you need, go to the file /config/services.php and add the above data in the following way:

We now need a function connected to the path testemail in order to do this, enter the /app/Http/Controllers/HomeController.php file and create the testEmail function.

Everything is ready to check if you have been able to go through the browser on the link /testemail, check if the email reached the target mailbox and enjoy the properly configured API!

Sign up for our newsletter

Join our mailing list and don't miss any posts and news from the tech world!