Configure AWS SES Mail Integration on Laravel.

{
"require": {
"aws/aws-sdk-php-laravel": "~3.0"
}
}

//Run the command for composer update = Composer update


//Put aws services in app.php

//In Laravel find the providers key in your config/app.php and register the AWS Service Provider.
'providers' => array(
// ...
Aws\Laravel\AwsServiceProvider::class,
)


//Find the aliases key in your config/app.php and add the AWS facade alias.
'aliases' => array(
// ...
'AWS' => Aws\Laravel\AwsFacade::class,
)

//Run this command

//php artisan vendor:publish --provider="Aws\Laravel\AwsServiceProvider"

//Run Command

//php artisan make:mail MailNotification

//command generates a class, which you’ll find at ‘app/Mail/MailNotification.php. The build() method of this class creates email messages:

//Compare Your code with this and replace
<?php

namespace App\Mail;

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

class MailNotification extends Mailable
{
use Queueable, SerializesModels;
public $details;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{

return $this->subject('Mail from .com')
->view('mail.template');
}
}


//Create Template blade in Resources/views/mail/template.blade.php

//Here i used simple template you can chnage
<!DOCTYPE html>
<html>
<head>
<title>test.com</title>
</head>
<body>
<h1>{{ $details['title'] }}</h1>
<p>{{ $details['body'] }}</p>

<p>welcome to mail! </p>
<p>Thank you</p>
</body>
</html>

//The settings can be found in the generated config/aws.php configuration file. By default, the credentials and region settings will pull from your .env file.

return [
'credentials' => [
'key' => env('AWS_ACCESS_KEY_ID', ''),
'secret' => env('AWS_SECRET_ACCESS_KEY', ''),
],
'region' => env('AWS_REGION', 'us-east-2'),
'version' => 'latest',
'ua_append' => [
'L5MOD/' . AwsServiceProvider::VERSION,
],


];



//Added some lines in mail.php

'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailtrap.io'),
'port' => env('MAIL_PORT', 2525),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),

//Final steps add
// Mail configuration in dashboard controller inside destroy function



$details = [
'title' => 'tittle',
'body' => 'This is for testing email sending by ---company'
];

\Mail::to('kk@gmail.com')->send(new \App\Mail\MailNotification($details));

dd("Email is Sent.");



--

--

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