How to send Email in Lumen using Mailgun.

1) Require illuminate/mail

$app->withFacades();$app->register(App\Providers\AppServiceProvider::class);
$app->configure('services');
$app->configure('mail');
$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

$app->alias('mailer', Illuminate\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\MailQueue::class);
<?php
return [
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
'endpoint' => env('MAILGUN_ENDPOINT')
],
<?php

return [
'driver' => env('MAIL_DRIVER', 'mailgun'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', ''),
'name' => env('MAIL_FROM_NAME', ''),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => env('MAIL_PRETEND', false),
'markdown' => [
'theme' => 'default',

'paths' => [
resource_path('views/vendor/mail'),
],
],

];
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=
MAIL_PASSWORD=
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=YourAddress
MAIL_FROM_NAME="Your from name"

MAILGUN_DOMAIN=yourmailgundomain
MAILGUN_SECRET=mailgunsecretkey
MAILGUN_ENDPOINT=api.mailgun.net
<?php


namespace App\Mail;


use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class DemoMail extends Mailable
{
use Queueable,SerializesModels;

public $data;

public function __construct($data){
$this->data = $data;
}



public function build()
{
return $this->subject('Email Sent Successfull')->view('emails.registration.welcome_email')
->with([
'user' => $this->data
]);
}
}
<!DOCTYPE html>
<html>
<head>
<title>Welcome</title>
</head>

<body>
<h2>Hello {{$user->name}}</h2>
<h4>Welcome to the Demo Mail</h4>
<p>Your demo is completed.</p>

</body>

</html>
use Illuminate\Support\Facades\Mail;
use App\Mail\UserMail;
use App\Mail\UserMail;use Illuminate\Support\Facades\Mail;
Mail::to($request->emailAddress)->send(new UserMail($request));

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Adding Fibonacci Numbers With Using Recursion Function

Python Branching and Loops

Why is my QMS software better than yours?

weekly.tf #36 — helm and k8s v2 providers

Experienced Front-End Developer Job at Anaeko EFED008

Date/Time and Daylight saving for Programmers

The Adapter Pattern — A Replacement To Dependency Injection

Concatenation in Python

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sagarvermaitdeveloper

Sagarvermaitdeveloper

More from Medium

Scores platform New Sprint— Best Goalscorer's

What Is Your Netw

10X.TV — DEVELOPMENT

Online Safety #03 DDoS Attacks