How to send email in laravel framework?

.env file

File name : index.php

MAIL_DRIVER=smtp
MAIL_HOST=mail.itechxpert.in
MAIL_PORT=587
MAIL_USERNAME=info@itechxpert.in
MAIL_PASSWORD=itechxpert_email_password
MAIL_ENCRYPTION=tls

.env file

File name : index.php

MAIL_DRIVER=smtp
MAIL_HOST=mail.itechxpert.in
MAIL_PORT=587
MAIL_USERNAME=info@itechxpert.in
MAIL_PASSWORD=itechxpert_email_password
MAIL_ENCRYPTION=tls

MAIL_FROM_ADDRESS=info@itechxpert.in
MAIL_FROM_NAME="${APP_NAME}"

.env file

File name : index.php

MAIL_DRIVER=smtp
MAIL_HOST=smtp.googlemail.com
MAIL_PORT=465
MAIL_USERNAME=mahtab.habib@gmail.comn
MAIL_PASSWORD=email_password
MAIL_ENCRYPTION=tls

MAIL_FROM_ADDRESS=mahtab.habib@gmail.com
MAIL_FROM_NAME="${APP_NAME}"

Make Configuration

File name : index.php

MAIL_DRIVER=smtp
MAIL_HOST=mail.taxplayers.in
MAIL_PORT=587
MAIL_USERNAME=info@taxplayers.in
MAIL_PASSWORD=email password
MAIL_ENCRYPTION=tls

Create Mail

File name : index.php

php artisan make:mail SendmailController

<?php

namespace App\Mail;

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

class SendmailController extends Mailable
{
use Queueable, SerializesModels;


public $data;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
//return $this->view('view.name');
return $this->subject('Mail from Taxplayers.in')->view('emails.email-send');
}
}

view emails/email-send.blade.php

File name : email-send.blade.php

<!DOCTYPE html>
<html>
<head>
<title>ittutorial.in</title>
</head>
<body>
<h1>{{ $data['title'] }}</h1>
<p>{{ $data['body'] }}</p>

<p>Thank you</p>
</body>
</html>

Add Route

File name : index.php

Route::get('send-mail', function () {

$data = [
'title' => 'Mail from Taxplayers',
'body' => 'We will Contact you shortly'
];

//\Mail::to('taxplayers786@gmail.com')->send(new \App\Mail\SendmailController($data));
\Mail::to('info@Taxplayers.in')->send(new \App\Mail\SendmailController($data));

echo "Email Succssfully Send";
});

File name : index.php

localhost/ittutorial/send-mail

File name : StreemBuffer.php

$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;

File name : index.php

private function establishSocketConnection()
{
$host = $this->params['host'];
if (!empty($this->params['protocol'])) {
$host = $this->params['protocol'].'://'.$host;
}
$timeout = 15;
if (!empty($this->params['timeout'])) {
$timeout = $this->params['timeout'];
}
$options = [];


if (!empty($this->params['sourceIp'])) {
$options['socket']['bindto'] = $this->params['sourceIp'].':0';
}

if (isset($this->params['stream_context_options'])) {
$options = array_merge($options, $this->params['stream_context_options']);

}




$options['ssl']['verify_peer'] = FALSE;
$options['ssl']['verify_peer_name'] = FALSE;






$streamContext = stream_context_create($options);

set_error_handler(function ($type, $msg) {
throw new Swift_TransportException('Connection could not be established with host '.$this->params['host'].' :'.$msg);
});
try {


$this->stream = stream_socket_client($host.':'.$this->params['port'], $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, $streamContext);
} finally {
restore_error_handler();
}

if (!empty($this->params['blocking'])) {
stream_set_blocking($this->stream, 1);
} else {
stream_set_blocking($this->stream, 0);
}
stream_set_timeout($this->stream, $timeout);
$this->in = &$this->stream;
$this->out = &$this->stream;




}

Add this part in config/Mail.php

File name : config/mail.php

'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info@itechxpert.in'),
'name' => env('MAIL_FROM_NAME', 'Itechxpert'),
],

Email Template 1

File name : format1.php

@component('mail::message')
# Dear, {{$content['name']}}

You are receiving this email because we received a signup request for your this mail account.

@component('mail::button', ['url' => 'taxplayers.in'])
Click Here
@endcomponent

If you did not request a signup , no further action is required.

Thanks,
{{ config('app.name') }}
@endcomponent

Email Template 2

File name : format2.blade.php

@component('mail::layout')
{{-- Header --}}
@slot('header')
@component('mail::header', ['url' => config('app.url')])
Header Title
@endcomponent
@endslot

{{-- Body --}}
This is our main message {{ $user }}

{{-- Subcopy --}}
@isset($subcopy)
@slot('subcopy')
@component('mail::subcopy')
{{ $subcopy }}
@endcomponent
@endslot
@endisset

{{-- Footer --}}
@slot('footer')
@component('mail::footer')
© {{ date('Y') }} {{ config('app.name') }}. Super FOOTER!
@endcomponent
@endslot
@endcomponent

Template 3

File name : format3.blade.php

<table class="wp-block-table action"><tbody><tr><td>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><a class="button button-{{ $color or 'blue' }}" href="{{ $url }}" target="_blank" rel="noopener">{{ $slot }}</a></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td><td>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><a class="button button-{{ $color or 'blue' }}" href="{{ $url }}" target="_blank" rel="noopener">{{ $slot }}</a></td>
</tr>
</tbody>
</table>
</td><td><a class="button button-{{ $color or 'blue' }}" href="{{ $url }}" target="_blank" rel="noopener">{{ $slot }}</a></td></tr><tr><td>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td><a class="button button-{{ $color or 'blue' }}" href="{{ $url }}" target="_blank" rel="noopener">{{ $slot }}</a></td>
</tr>
</tbody>
</table>
</td><td><a class="button button-{{ $color or 'blue' }}" href="{{ $url }}" target="_blank" rel="noopener">{{ $slot }}</a></td></tr><tr><td><a class="button button-{{ $color or 'blue' }}" href="{{ $url }}" target="_blank" rel="noopener">{{ $slot }}</a></td></tr>
</tbody>
</table>





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here


Ittutorial