- How do I send an email in Laravel using resend/resend-php?
- Initialize the client with your Resend API key, then use `$resend->emails->send()` with an associative array containing `from`, `to`, `subject`, and `text` or `html`. Example: `$resend->emails->send(['from' => 'contact@example.com', 'to' => 'user@example.com', ...])`. Works seamlessly alongside Laravel’s Mailables or as a standalone solution.
- Does resend/resend-php support Laravel’s queue system for delayed emails?
- No, but you can wrap the client in a Laravel job or use Resend’s server-side automations for delayed emails. For example, trigger an automation via `Resend::automations()->trigger('abandoned_cart', $data)` instead of queuing a Mailable. This offloads delays to Resend’s infrastructure.
- What Laravel versions are compatible with resend/resend-php?
- The package requires PHP 8.1+, which aligns with Laravel 10+. For Laravel 9 or older, you’ll need to manually patch the PHP version dependency or use a fork. Always check the [GitHub repo](https://github.com/resend/resend-php) for updates on Laravel-specific integrations.
- Can I use Resend automations to replace Laravel’s manual email workflows?
- Yes. Replace Laravel’s queued Mailables (e.g., abandoned cart emails) with Resend automations. Trigger them via Laravel events or console commands, then let Resend handle retries and delays. Example: `Resend::automations()->trigger('welcome_series', ['user_id' => $user->id])`. Reduces backend logic and leverages Resend’s reliability.
- How do I handle Resend webhooks (e.g., email.bounced) in Laravel?
- Use Laravel’s `route:web` middleware to receive webhooks at `/resend/webhook`. Validate signatures with Resend’s `X-Resend-Signature` header, then dispatch Laravel events or queue jobs. Example: `ResendEvent::dispatch($event)` for idempotent processing. The package doesn’t include webhook handling by default—implement it in your `routes/web.php`.
- What’s the best way to mock Resend in Laravel tests?
- The package doesn’t include a fake system, but you can mock the `Resend` facade or client using Laravel’s `Mockery` or `createMock()`. Example: `$this->mock(Resend::class)->shouldReceive('emails->send')->once()`. For automations, stub the `trigger()` method. Test edge cases like API failures by throwing exceptions in your mocks.
- Are there alternatives to resend/resend-php for sending emails in Laravel?
- Yes. For transactional emails, consider Laravel’s built-in `Mail` facade, `spatie/laravel-mailables`, or third-party APIs like Mailgun (`mailgun/mailgun-php`), SendGrid (`sendgrid/sendgrid`), or Postmark (`postmark/php-sdk`). Resend stands out for its serverless automations and developer-friendly API, but compare pricing and features for your use case.
- How do I configure Resend tracking domains in Laravel?
- Use the `trackingDomains` resource to configure domains via `Resend::trackingDomains()->create(['domain' => 'track.yourdomain.com', 'subdomain' => 'u'])`. Store the API key in Laravel’s `config/services.php` and bind the Resend client in a service provider. Sync tracking data with Laravel’s analytics tools like Scout or Mixpanel via webhooks or scheduled jobs.
- What happens if Resend’s API fails during an automation trigger?
- Implement a fallback by catching exceptions and triggering a Laravel job or Mailable as a backup. Example: `try { Resend::automations()->trigger(...); } catch (Exception $e) { Email::send(new FallbackWelcomeEmail($user)); }`. Log failures for monitoring and alerting.
- Can I use resend/resend-php in non-Laravel PHP projects?
- Absolutely. The package is framework-agnostic and works in any PHP 8.1+ project. Initialize the client with `Resend::client('your_api_key')` and use the same `emails->send()` or `automations->trigger()` methods. The Laravel-specific examples in the docs are optional—focus on the core API for plain PHP.