Why email sending is not simple anymore
Reasons why emails may fail to be delivered:- Technical error of your programming script
- Blocked by your hosting provider while sending
- Reached the email sending rate limit set by your hosting provider
- Blocked by recipient server because of "bad reputation" of your hosting provider server
- Went to SPAM or another automatically filtered folder
- Went to GMail tab like "Promotions"
- etc.
Third-party email sending providers
To solve most of the problems listed above, you can use a service to deliver email for you. Whenever you want to send an email, you just call that service's function, and they take care of the deliverability for you, usually promising 99%+ guarantee. They do that by providing their own whitelisted servers which have a really good sending reputation, for sending good quality email. They care about that reputation a lot, so the also fight against spammers in their own system. So if you try to send spam or unsolicited email via their servers, guess what - they will block your account and your domain name then gets blacklisted. These are the most popular services: Important notice - those services are not free. For large amount of email, that is. Each of them has its own "free tier" limit - like, Mailgun allows 10,000 emails per month (but you still need to put in your credit card, it just won't be charged until the limit is reached). Let's look at the prices for the lowest tiers, as it stands in July 2018*:Provider | Free Tier | Lowest Price after Free Tier |
---|---|---|
Mailgun | 10,000 emails per month | $5 per 10,000 emails per month |
Sparkpost | 15,000 emails per month | $9 per 50,000 emails per month |
Amazon SES | - | $0.10 per 1,000 emails |
Sendgrid | 100 emails per day | $9.95 per 100,000 emails per month |
Mandrill (part of Mailchimp) | - | $40 per 50,000 emails per month |
Mailjet | 6,000 emails per month | $8.04 per 30,000 emails per month |
SendInBlue | 300 emails per day | 19 EUR per 40,000 emails per month |
It's not only about the price. You will have to not only register on their website, but also verify your domain name, which you will use for sending, like [something]@laraveldaily.com. You will have to update DNS records into your domain settings. It's quite technical, here's an example instruction from Mailgun. It may look really complicated, but that's the only way these services can actually provide quality email delivery.
How to use third-party providers in Laravel
There are three providers which are supported by default in Laravel:- Mailgun
- Sparkpost
- Amazon SES
'mailgun' => [ 'domain' => 'your-mailgun-domain', 'secret' => 'your-mailgun-key', ], 'sparkpost' => [ 'secret' => 'your-sparkpost-key', ], 'ses' => [ 'key' => 'your-ses-key', 'secret' => 'your-ses-secret', 'region' => 'ses-region', // e.g. us-east-1 ],And then you use default Laravel Mail::send() functionality, that's it! I personally use Mailgun and have no problem with it, so can recommend to you, too. If you want to use any service outside of those three, you need to find their documentation on integration with Laravel. It probably will be some API calls, or getting you SMTP details, so you would use Laravel's smtp driver. Final tip: you can use services for temporary email testing which send all the emails into a "virtual inbox", no matter the recipient. For our team we use Mailtrap.io.
Very useful, thanks
good 👍 👍
Very useful, thanks