Laravel
Learn how to send your first email using Laravel.
Prerequisites
To get the most out of this guide, you will need to:
1. Install
First, install Resend for Laravel using the Composer package manager:
2. Configuration
API key
Next, you should configure your Resend API key in your application’s .env
file:
Mail driver
To use Resend as your mail driver, first create a new mailer definition, in the mailers
array within your application’s config/mail.php
configuration file:
Next, update your application’s .env
file to use the Resend mail driver:
3. Send an email
Resend for Laravel provides two convenient ways to send emails, using Laravel’s email service or the Resend
API facade.
Using the Mail Facade
Using the Resend Facade
4. Receiving webhook requests
By default, Resend for Laravel includes a webhook controller to respond to the /resend/webhook
URL path. The controller will dispatch a Laravel event that corresponds to a Resend event. For example, an email.delivered
event type will send an EmailDelivered
Laravel event.
Register the webhook endpoint
Register your publicly accessible HTTPS URL in the Resend dashboard.
For development, you can create a tunnel to your localhost server using a tool
like ngrok. For example:
https://8733-191-204-177-89.sa.ngrok.io/resend/webhook
CSRF protection
Webhook requests from Resend need to bypass Laravel’s CSRF protection. Be sure to list the URI as an exception in your application’s App\Http\Middleware\VerifyCsrfToken
middleware or list the route outside of the web middleware group:
Verifying webhook signatures
To enable webhook verification, ensure that the RESEND_WEBHOOK_SECRET
environment variable is set in your application’s .env
file. The Signing secret can be retrieved from your Resend dashboard.
5. Try it yourself
Laravel Example
See the full source code.
Was this page helpful?