Email Configuration
Laravel supports a variety of mail transport drivers to be used while sending an e-mail. Today we will walk you through two types of email service configuration step by step. We will discuss Mailgun and Gmail SMTP configuration here.
Mailgun Configuration
Sandbox domains are restricted to authorized recipients only. If you want to receive your email in sandbox account. Please authorize your email. Up to 5 Authorized Recipients can be added.
For more information, Please follow Authorized Recipients
To setup and configure Mailgun you need to set these below .env
keys. We will discuss how you can get those env variable from mailgun.
MAIL_MAILER=MAIL_HOST=MAILGUN_DOMAIN=MAILGUN_SECRET=MAIL_FROM_ADDRESS=MAIL_PORT=587MAIL_USERNAME=nullMAIL_PASSWORD=nullMAIL_ENCRYPTION=nullADMIN_EMAIL=support@example.com
MAIL_MAILER=mailgun
MAIL_HOST=smtp.mailgun.org
To get
MAILGUN_DOMAIN
Create or SignIn a Mailgun account from here https://login.mailgun.com/login After login click sending you will see a domain list there. I will go with this domain below. Just copy this domain and set this as yourMAILGUN_DOMAIN
Now to obtain
MAILGUN_SECRET
click on on that domain. You will redirect to an over page like below click on API Keys.Then it will redirect to page find
Mailgun API keys
then click onAdd new key
To set
MAIL_FROM_ADDRESS
just type your mail address.Now go to the dashboard -> sending -> Domain Click on the domain then select SMTP. You will see
MAIL_PORT=587MAIL_USERNAME=null
configuration information there like below.
In a Mailgun configuration, you typically don't need to specify a
MAIL_PASSWORD
because Mailgun uses API keys for authentication, not SMTP passwords. You can setMAIL_PASSWORD=null
or remove it from your .env file.Set your MAIL_ENCRYPTION
MAIL_ENCRYPTION=tls
You can set your admin email
ADMIN_EMAIL=your_email@example.com
Gmail SMTP Configuration
To setup Gmail SMTP Configuration you need to set these below .env
keys. We will discuss how you can get those env variable from Gmail.
MAIL_MAILER=MAIL_HOST=MAILGUN_DOMAIN=MAILGUN_SECRET=MAIL_FROM_ADDRESS=MAIL_PORT=587MAIL_USERNAME=nullMAIL_PASSWORD=nullMAIL_ENCRYPTION=nullADMIN_EMAIL=support@example.com
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
You can ignore
MAILGUN_DOMAIN
MAILGUN_SECRET
for gmail.To set
MAIL_FROM_ADDRESS
just type your mail address.MAIL_PORT=587
To set
MAIL_USERNAME=your@gmail.com
just type your gmail address that you are using for configuration.To get MAIL_PASSWORD from google Create or SignIn to a gmail account. Then go to your account or click the URL https://myaccount.google.com/security Then turn on 2-Step Verification.
Under 2-Step Verification settings you will see app passwords and click that -
now set your application name under other (custom name)
after typing the name click on generate a propt will popup. like below That is your
MAIL_PASSWORD
copy that.Set your MAIL_ENCRYPTION
MAIL_ENCRYPTION=tls
You can set your admin email
ADMIN_EMAIL=your_email@example.com