Get "PHP 8 in a Nuthshell" (Now comes with PHP 8.3)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

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.

Learn the fundamentals of PHP 8 (including 8.1, 8.2, and 8.3), the latest version of PHP, and how to use it today with my new book PHP 8 in a Nutshell. It's a no-fluff and easy-to-digest guide to the latest features and nitty-gritty details of PHP 8. So, if you're looking for a quick and easy way to PHP 8, this is the book for you.

Like this article? Consider leaving a

Tip

👋 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.

Comments?