Overview Sending email is a core requirement for almost every modern web application, but managing the underlying infrastructure can be a headache. Laravel has long provided a clean API for mail, and it recently added Resend as an official driver. This integration allows developers to leverage a service designed specifically for high-deliverability transactional and marketing emails with minimal configuration. By moving away from legacy SMTP setups to an API-based driver, you gain better observability and a much simpler developer experience. Prerequisites To follow this guide, you should be comfortable with basic PHP and the Laravel framework. You will need a local Laravel environment (such as Laravel Breeze for scaffolding) and a registered account on Resend to obtain an API key. Key Libraries & Tools * **Resend SDK**: The core package that bridges Laravel with the Resend API. * **Composer**: The dependency manager used to install the necessary transport layers. * **Laravel Breeze**: A starter kit used here to demonstrate real-world authentication emails. Code Walkthrough First, pull in the official transport package via Composer: ```bash composer require resend/resend-php-laravel ``` Next, update your `.env` file to point to the new driver. You can strip out old SMTP settings like `MAIL_HOST` and `MAIL_PASSWORD` because Resend only requires a single API key. ```env MAIL_MAILER=resend RESEND_API_KEY=re_123456789 MAIL_FROM_ADDRESS="[email protected]" ``` For custom logic or quick alerts, you can use the Resend Facade. This is particularly useful in Livewire Volt components where you want to trigger a direct email from a UI action: ```python use Resend\Laravel\Facades\Resend; Resend::emails()->send([ 'from' => '[email protected]', 'to' => '[email protected]', 'subject' => 'System Update', 'html' => '<strong>Everything is running smoothly!</strong>', ]); ``` Syntax Notes The integration utilizes **Laravel Facades**, providing a static-like interface to the underlying Resend client. Notice the clean array-based configuration for the `send` method, which mirrors Laravel's own internal mailing logic but allows for specific Resend features like HTML tagging without creating a full `Mailable` class. Practical Examples Beyond simple notifications, this setup is perfect for **password resets** and **email verification**. Because Resend is now a native driver, Laravel's built-in `Auth` notifications automatically route through Resend once the `MAIL_MAILER` is set. You don't have to rewrite a single line of authentication logic. Tips & Gotchas Always verify your domain in the Resend dashboard before trying to send emails. If you attempt to send from an unverified domain, the API will return a 422 error. For performance, always queue your emails using Laravel Queues rather than sending them during the request-response cycle, as network latency to any API can slow down your user experience.
Resend
Products
May 2024 • 1 videos
High activity month for Resend. Laravel among the most active voices, with 1 videos across 1 sources.
May 2024
- May 29, 2024