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.
7108
5
All Comments (5)
Chun published at: 2020-01-16 13:37:26
Hi,Hello How Are You Today?I found you on web and I in reality liked your work. You pull off NOT need to bother approximately paying for hosting, auto emailing service, and domain name. Online Traffic has in its system an automaker that is easy to use. You just dependence to click on the alternating categories of leads and send an email to them via the auto mailer upon the website. Join here: https://leadsmarketing.ucraft.net/ Let's outlook it, no matter how good your opportunity or product is, you are not going to make any sales and build your opt in list if nobody sees your offer. To your success!
Dawn published at: 2019-11-05 09:04:26
Invite Bloggers and Webmasters to Fill out Paid Surveys I'm Dawn from Centtip. We are working with Inboxdollars to provide bloggers another opportunity to earn cash or get rewards. After joining Inboxdollars, you will be able to get rewards by sharing your opinions online ( Or Earn From Live Sex Cams). Paid surveys have been prepared for you: https://www.centtip.xyz/paidsurvey Regards, Dawn Frasure Unsubscribe: https://www.centtip.xyz/unsubscribe
Chung published at: 2019-09-28 09:26:24
It is very helpful. Thanks.0
Maryetta published at: 2019-09-26 13:34:21
Invite You to Test Our Product Hi,   I am Maryetta and the founder at Biglep. I’m reaching out to you because we are looking for health enthusiasts like you to test our prouct Rejuvenated Energy™. Rejuvenated Energy™ can help you Loss Weight, boost energy, and create a lasting feeling of rejuvenated wellbeing. We have prepared 1 jar for you. Get it at No Cost : https://www.biglep.com/loseweight Regards, Maryetta Baldyga UNSUBSCRIBE : Reply "no"
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