728x90 AdSpace

  • Latest News

    Tuesday 14 July 2020

    [PHP - LARAVEL] Using Gmail SMTP Server to send Email in Laravel

    Hello everyone, welcome back to Learn Tech Tips blogspot.

    Topic today is show you how to using gmail SMTP server to send mail in Laravel.
    At times the simplest things are the most complicated. Here I would be making the very first attempt to further simplify the simpler things . So lets get started :
    I would divide this implementation into 2 parts :

    Step 1: Creating / Using an existing Gmail account to create app passwords.
    Step 2: Adding the Gmail account details to the Laravel Application.

    Let check step 1 first:
    Step 1: Creating / Using an existing Gmail account to create app password:
    I would be using my existing Gmail account , but in case if you wish to create a new account , you can do so using this Link

    Next we need to enable 2 step Verification in Gmail as follows:
    Login into Gmail .
    To be able to create app passwords we need to first enable 2 Step Verification .
    Click on the user icon and select “Google Account” .
    Next we need to select Security from the left nav , then select “2 Step Verification” . (Doing this would ask you to login again and then Gmail would authenticate you further using OTP )

    Using Gmail SMTP Server to send Email in LaravelAdd caption





    Now we generate the app password that we would be using in the Laravel Application , again clicking on the Google Account in the user icon ->Security ->App Passwords . (This would again ask you to login and then authenticate using OTP)


    We need to select “Mail” as the app and “Other (Custom name)” as the device from the drop downs .

    Selecting this would ask you to add the name of the Application for which you wish to generate the password and once added click GENERATE.


    Using Gmail SMTP Server to send Email in Laravel


    This would open a pop up with your 16 character app password . (Kindly copy this and keep it safe).
    We are all set to add these detail’s to the Application.

    Step 2: Adding Gmail Account detail’s to the Laravel Application:
    We need to edit the following in the .env file

    MAIL_DRIVER=smtp
    MAIL_HOST=mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    MAIL_ENCRYPTION=null


    with

    MAIL_DRIVER=smtp
    MAIL_HOST=smtp.gmail.com
    MAIL_PORT=465
    MAIL_USERNAME=youraccount@gmail.com
    MAIL_PASSWORD=yourapppassword
    MAIL_ENCRYPTION=ssl


    NOTE: There is no need for us to make any change in the config/mail.php file

    If you got question or feeback, free feel to leave your comment at below this blog.
    Many thanks!

    Zidane

    • Blogger Comments
    • Facebook Comments

    0 comments:

    Post a Comment

    Item Reviewed: [PHP - LARAVEL] Using Gmail SMTP Server to send Email in Laravel Rating: 5 Reviewed By: Unknown
    Scroll to Top