ONE NET WIKI Free and professional IT Wiki

How to send an email via Gmail SMTP Server in Laravel

2018-09-04 ONE NET WIKI

1.jpg

In order to send an email via Gmail SMTP Server in Laravel, you may follow the following directions.

1. Gmail account setup

  • Login to your gmail account;

2.png

  • Select Google account > Sign In & Security > Sign in to google:

    enable two step verification [Enter your password again and a unique verification code that's sent to your phone], then generate app password, and you can use that app password in .env file.

3.png

  • Select Google account > Sign In & Security > Apps with account access (if necessary):

    enable "Allow less secure apps".

4.png

2. Laravel configuration setup

.env file will look like this:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=<your_email_address>
MAIL_PASSWORD=<your_gmail_app_password_>
MAIL_ENCRYPTION=tls

or like this:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=<your_email_address>
MAIL_PASSWORD=<your_gmail_app_password_>
MAIL_ENCRYPTION=ssl

dont-forget-to-remember.jpg

Note: Don't forget to run "php artisan config:cache" after you make changes in your .env file.

3. Laravel controller file:

$data = array('name'=>"Joshua", "body" => "This is my first Online Email.");
Mail::send('emails.mail', $data, function($message) {
  $message->to('TO_EMAIL_ADDRESS', 'To Website')
          ->subject('Online Email Test');
  $message->from('FROM_EMAIL_ADDRESS','From Visitor');
});

4. Laravel View file:

resources->views->emails->mail.blade.php

Hi <strong>{{ $name }}</strong>,

<p>{{ $body }}</p>
Editor's Note: All the articles in this website are original. If reproduced, please indicate the source and link.
3975
1
All Comments (1)
Trish published at: 2019-04-29 14:04:08
Invite You to Review Our Product Hi,   I am Trish from the American Beauty Association. I’m reaching out to you because we are looking for beauty enthusiasts like you to test our makeup brush. Go here:www.centtip.xyz to test the Mieoko Flat Top Brush * Perfect for medium to heavy coverage that doesn't look caked on * Does not soak up excessive amounts of product. * 22,000 mink soft bristles for flawless powder or liquid makeup application * Does Not Shed! Thank you for your time, Trish
Expand to publish a comment

Web Development


Web Management


Web Marketing


Web Security