Laravel Mailgun Setup Example

By Hardik Savani November 5, 2023 Category : Laravel Mailgun API

Mailgun is very popular API to send email from website. It is very fast to send mail and also it track the mail. Tracking email is very important feature of mailgun api and you can also see how much user open your mail, click on your mail too. Mailgun send mail like work gun. In this post i would like to show you how to setting of mailgun in our laravel 5 application. In this example you can learn to send simple mail using mailgun api. If you are use mailgun for sending email then you can save loading time and you can get mail fast.

First we will add configration on mail. i added my gmail account configration. so first open .env file and bellow code:






Ok, now we need to add secret and domain of mailgun api configration. So first create new account in SignUp if you don't have before. After registeration active your mailgun account and click on Domails and click on Add New Domail button. then you can see bellow screen.

After add name you can see bellow screen and copy domain name and API Key from like bellow image.

Now you have to open services.php and add mailgun configration this way :


 'mailgun' => array(

'domain' => '',

'secret' => 'key-11796c09e58-056a9e975c96dd334da0dd',


Now we are ready to send mail for test so first create test route for email sending.


Route::get('mail', 'HomeController@mail');

Ok, now add mail function in HomeController.php file so add this way :


public function mail()


$user = User::find(1)->toArray();

Mail::send('emails.mailEvent', $user, function($message) use ($user) {


$message->subject('Mailgun Testing');


dd('Mail Send Successfully');


At last create email template file for send mail so let's create mailEvent.blade.php file in emials folder.



Hi, I am from from mailgun testing.

Now try...