Laravel Send Emails Mailgun setup Tutorial

Today, We want to share with you Laravel Send Emails Mailgun setup Tutorial.In this post we will show you Mailgun setup with Laravel 5 example, hear for Emails with Laravel 5.7 Mailables we will give you demo and example for implement.In this post, we will learn about Send email in Laravel through email sending services with an example.

Laravel Send Emails Mailgun setup Tutorial

There are the Following The simple About Laravel Send Emails Mailgun setup Tutorial Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel Send Emails Using PHP Mailgun , so the some How To Send Email In Laravel Tutorial for this example is following below.

  • Laravel configration(.env file)
  • Global Setting Of the Mailgun
  • Define Laravel Route
  • Create a Controller
  • Laravel Send Email Template View File
Also Read :  Simple Print AngularJS Hello World program From scratch

Sttep 1 : setting of the Laravel configration

open .env file and bellow code

add configration on mail Sending Emails with Laravel and Mailgun

MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
[email protected]
[email protected]
MAIL_ENCRYPTION=tls

Good, now I required to Include secret key as well as your domain of mailgun send mail api configration. Therefor I make a new account in offical website mailgun.com SignUp and then I registeration and active your simple step to mailgun new account as well as click on simple tabs Like Domails Into Add New Domail button.

Step 2 : Global Setting Of the Mailgun

config/services.php

And then We have to open Laravel services.php file as well as put here simple mailgun configration key and url this way :

 'mailgun' => array(
    'domain' => 'pakainfo.com',
    'secret' => 'key-225487c09e58-056a9e692c96dd832jd0cc',
),

Step 3 : Define Laravel Route

app/Http/routes.php

Also Read :  Angular 6 Reactive Forms Validation Tutorial Example

After I am step 3 ready to each client send mail for first welcome so first usnig laravel 5.4, 5.5, 5.6 and 5.7 make welcome route for email sending.

Route::get('mail', '[email protected]');

Step 4 : Create a Controller

app/Http/Controllers/SendMailController.php

Good way, Then add simple send mail function in SendMailController.php file there for add Laravel this way :

public function mail()
{
    $client = Client::find(1)->toArray();
    Mail::send('emails.simpleSendMailTemplate', $client, function($message) use ($client) {
        $message->to($client->email);
        $message->subject('Laravel Mailgun Testing');
    });
    dd('Mail Send Successfully');
}

Laravel mailgun Send Mail
////////mailgun///////////
      try {
            $data = [
                'title'=>'Email'
            ];
            $sent = Mail::send('emails.simpleSendMailTemplate', $data, function($message) {
                $message->from('[email protected]', 'Example Person');
                $message->to('[email protected]');
                $message->subject('Laravel Send Emails Mailgun setup Tutorial - Mailgun Testing');
            });
            if( ! $sent) dd("something wrong");
            dd('Mail Send Successfully');
        }
        catch (GenericHTTPError $e) {
           // return $e->getMessage();
            dd($e->getMessage());
        }

Step 5 : Laravel Send Email Template View File

resources/views/emails/simpleSendMailTemplate.blade.php

At Final step to make Laravel email template file for mailgun send mail therefor let’s make a simpleSendMailTemplate.blade.php file in emials folder.

Also Read :  Laravel Autocomplete text field suggestions search using Database

<h1>Laravel Send Emails Mailgun setup Tutorial</h1>
Hi, I am from pakainfo.com from mailgun testing.

Thanks
Jaydeep Gondaliya

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel Send Emails Mailgun setup Tutorial.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Recommended For You.

Laravel Group By Count Multiple Columns
Today, We want to share with you Laravel Group By Count Multiple Columns.In this post we will show you ,

Add a Comment

Your email address will not be published. Required fields are marked *