Sending mails using Resend in Laravel
When it comes to sending emails, Laravel makes it a breeze of a task. Be it SMTP, Sendmail, Mailgun, or any other service, Laravel has got it all. You set the default mailer, the required API key/token in the .env
file, and you are good to go.
The recent addition to this list is the email provider called Resend. Essentially, Resend is now a part of Laravel core so all you need is to install the Resend SDK, set the Resend API key in the .env
file and you’ll able to send emails in no time.
To get started, install the Resend SDK using Composer.
composer require resend/resend-php
Once done, you need to set the default
option in your application’s config/mail.php
configuration file to resend
.
'default' => 'resend',
Finally, you need to add the following line of code to your config/services.php
file if it’s not already there.
'resend' => [
'key' => env('RESEND_KEY'),
],
Don’t forget to set the RESEND_KEY
environment variable in your .env
file. You can generate a new key from the API Keys section of your Resend account.
And that’s all you need to do to start sending emails using Resend in your Laravel application.
Caution: To send emails using Resend, you must verify your domain in your Resend account beforehand. Failing to do so will result in the following error.
Request to Resend API failed. Reason: The example.com domain is not verified. Please, add and verify your domain on https://resend.com/domains.
If you want to learn more about it, Aaron Francis has got you covered in this video.
Like this article?
Buy me a coffee👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.