Home Laravel How to send mail using mailgun in laravel?

How to send mail using mailgun in laravel?

by Shahriar Sagor

Hi All,
Now, We see a article of laravel mailgun integration. We can see laravel send mail using mailgun.Now i’m going to show you about laravel send mail mailgun setup. In this article, i will implement a laravel mailgun tutorial. Let’s see bellow example of laravel mailgun integration.

We can easily setup mailgun for email send in laravel 6, laravel 7 and laravel 8 application.

Now in this post, i will give you step by step instructions for send email in laravel application by using mailgun. Now you can create blade file design and also with dynamic information for mail layout. So now see step by step guides for sending email by using laravel as your requirement.

Step 1: Add Configuration

First we need to create account at mailgun if you don’t have any account. So first of all click bellow link to create account:

Mailgun Site

After successfully creating account we will get mail configuration as mail host, mail port, mail username, mail passwor.

Domain Page: Sending->Domain

In Domain Detail page -> Click to SMTP

Get SMTP Details

Add Receiver Email for Testing:

add details from there bellow:



Read Also : How to Base64 Image Upload in Laravel?

Step 2: Create Mail

Now in this step we will create mail class MyTestMails for email sending. Here i will write code for which view will call and object of user. So let’s run bellow command.

php artisan make:mail MyTestMail


namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class MyTestMail extends Mailable
    use Queueable, SerializesModels;
    public $details;
     * Create a new message instance.
     * @return void
    public function __construct($details)
        $this->details = $details;
     * Build the message.
     * @return $this
    public function build()
        return $this->subject('Mail from codingspoint.com')

Step 3: Create Blade View

In this step, i will create blade view file and write email that i want to send. Now i just write some dummy text. create bellow files on “emails” folder.


<!DOCTYPE html>
    <h1>{{ $details['title'] }}</h1>
    <p>{{ $details['body'] }}</p>
    <p>Thank you</p>

Read Also : Laravel 8 Sanctum API Authentication

Step 4: Add Route

Now at the last i will create “MyTestMails” for sending our test email. so let’s create a web route for testing send email.


Route::get('send-mail', function () {
    $details = [
        'title' => 'Mail from codingspoint.com',
        'body' => 'This is for testing email using smtp'
    \Mail::to('your_receiver_email@gmail.com')->send(new \App\Mail\MyTestMails($details));
    dd("Email is Sent.");

Now you can run and check example.

Run Project:

php artisan serve

You may also like