Gmail SMTP


Many web servers don’t allow to send mail directly from the server for the security purpose. So, Today we are going to learn Laravel SMTP send mail using Gmail SMTP. Also, Let’s see how we can send mail using Laravel Gmail SMTP. We can easily set up the SMTP driver for the Laravel application.

First of all, We are going to install Laravel step by step if not installed

Laravel SMTP send mail using Gmail SMTP

Once we are ready with Laravel let’s start the Laravel SMTP setting using Gmail SMTP step by step. Let’s open the “.env” file then follow the instruction

  1. First, we need to change the MAIL_DRIVER to smtp
  2. We need to set up the MAIL_HOST like “smtp.gmail.com” or “mail.domainname.com
  3. We need to set up the MAIL_PORT correct port for TLS and SSL like 587, 445, 25 etc…
  4. provide the username for the authentication MAIL_USERNAME
  5. provide the password for the authentication MAIL_USERNAME
  6. set up the encryption MAIL_ENCRYPTION for the authentication SMTP detail

After, setting up the server detail “.env” look like

Finally, We are ready with the SMTP If you are using Gmail as SMTP server then make sure don’t forget to enable Less Secure app.

Now, let’s check Laravel SMTP is working on not by sending the mail using Laravel like.

Now, let’s create the email template laravelhive.blade.php into the “resources/views/emails” directory.

Finally, We are ready for sending the testing email by following “http://localhost:8000/send-mail” URL.

If you face any issue with sending mail using Laravel SMTP write the comment below.