Prerequisites
Before getting started, you’ll need to:- Authorize your sending domain
- Create and retrieve your SendLayer API key
Installation
Install the SendLayer PHP SDK using Composer:Storing your API key
Create a.env file in your project root and add your API key:
.env
env() from application code. Config caching in production returns null for direct env() calls outside config files.
config/sendlayer.php
Registering the client in the container
Bind the client as a singleton inAppServiceProvider. Laravel then builds one instance per request lifecycle and injects it wherever you type-hint it.
app/Providers/AppServiceProvider.php
Sending an email from a controller
Type-hint the client in the constructor. Laravel resolves it from the container automatically.app/Http/Controllers/ContactController.php
validate() method rejects malformed payloads with a 422 response before the SDK runs. The replyTo field points at the person who filled in the form, so support agents can reply from their inbox.
Add the route:
routes/api.php
Use a
from address on a domain you authorized in SendLayer. Requests from an unauthorized domain fail.Rendering email bodies with Blade
Blade views give you layouts, components, and partials.resources/views/emails/welcome.blade.php
view() helper, then pass the result as the html parameter.
app/Jobs/SendWelcomeEmail.php
tags array labels the message. Tags appear in your event history, which helps you separate welcome emails from other traffic.
Testing the endpoint
Start the development server:Include the
Accept: application/json header. Without it, Laravel returns validation errors as a redirect rather than JSON.Next steps
PHP SDK Reference
Review every method and parameter in the PHP SDK.
Managing Webhooks
Create, list, and delete webhook subscriptions.
Retrieving Events
Query delivery events for any message.
Rate Limits
Understand recipient and request limits.