Guides
Laravel
How to send emails with Unsent in Laravel
Introduction
This guide shows how to send emails using Unsent in a Laravel application. You can use the Unsent PHP SDK or SMTP.
Send Email
You can send emails using the Unsent client.
use Unsent\Unsent;
use Illuminate\Support\Facades\Route;
Route::get('/send-email', function () {
$unsent = Unsent::client(env('UNSENT_API_KEY'));
$result = $unsent->emails->send([
'from' => 'Acme <onboarding@unsent.dev>',
'to' => ['delivered@unsent.dev'],
'subject' => 'Hello world',
'html' => '<strong>It works!</strong>',
]);
return $result;
});Using SMTP
Alternatively, you can use Laravel's built-in SMTP driver.
MAIL_MAILER=smtp
MAIL_HOST=smtp.unsent.dev
MAIL_PORT=587
MAIL_USERNAME=unsent
MAIL_PASSWORD=un_...
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="onboarding@unsent.dev"
MAIL_FROM_NAME="${APP_NAME}"