Configure SMTP to send Emails in Laravel

7 yearsago Read time : 1 Minute

Getting Started

First of all, you need to get a service from an SMTP Email service provider and configure smtp to your app, they will provide you SMTP credential for sending email using your Laravel Application. You can also ask your hosting provider first if they allow you to send SMTP email, so you can send email also from your hosting provider SMTP credential.

I am going to tell you all the possible ways to send or enable email from Laravel, although it’s the same way as you send Email from PHP, we will do it the Laravel way.

Lists of SMTP Email Providers

Amazon SES
Cheapest email service provider, see there Pricing.
Free plan – Amazon SES lets you send 62,000 emails/month free if you are an EC2 user (EC2 users are those users who purchase the Amazon service). Additionally, you will also receive 1,000/month for free.
Price – They will charge you only $0.10 per thousand emails, which is $1 for sending 10,000 emails

SendGrid

SendGrid is also a better service for sending emails, Also you can set your schedule campaigns to send emails a specific time.
SendGrid offers 12,000 emails completely free per month. It provides a PHP library to send email from any PHP application. But as we are using Laravel, we do not need any library.

Laravel offer the best email library called SwiftMailer PHP Library since it’s first version to get engage with your customers or subscribers.

Mailgun
Mailgun is one of the best SMTP email service provider that lets you send 10,000 emails per month for free, and $15 for 40,000 emails. It’s is easy to use. You can also access their API or dashboard to monitor your email stats.

I’ve listed the effective ones here. You can either signup for any of these email providers or you can choose any other who will provide you SMTP credentials.

Setting SMTP to Laravel

Configure smtp credential to .env file in your root directory and save, an example is below

MAIL_DRIVER=smtp
MAIL_HOST=smtphost
MAIL_PORT=2525
MAIL_USERNAME=[SMTP_USERNAME]
MAIL_PASSWORD=[SMTP_PASSWORD]
MAIL_ENCRYPTION=null

That’s it, your application should now start sending emails if your application has email sending features, or you can write code for sending emails. Get email example from Laravel documentation

https://laravel.com/docs/5.1/mail


About the Author

themeqx