26.5 C
Pakistan
Wednesday, May 29, 2024

Laravel and PHP Email Package for Resending

A package called Resend for Laravel offers mailers integration with the Resend API. Because of this API’s developer-friendly design, creating and sending emails is a breeze.

The simplest illustration of how simple it is to send an email directly using the Resend API is provided here:

$resend = Resend::client('re_123456789');
 
$resend->emails->send([
  'from' => 'from@example.com',
  'to' => 'to@example.com',
  'subject' => 'hello world',
  'html' => '<strong>it works!</strong>',
]);

You can use the Laravel version’s facade to email the API directly or to integrate it as a mailer:

// Using the API
Resend::email()->send([
    'from' => 'from@example.com',
    'to' => $request->user()->email,
    'subject' => 'hello world',
    'html' => (new OrderShipped($order))->render(),
]);
 
// Via the Mail facade
Mail::to($request->user())->send(new OrderShipped($order));

If you’d like to see more examples, there is a example repo for Laravel and a vanilla PHP example. The official docs have everything you need to set up Resend in Laravel along with the API reference docs.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles