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:Usage
After installation, you’re ready to integrate the SDK into your code. The SDK includes modules for sending emails, managing webhooks, and retrieving events.Sending an Email
Create or edit a.php file. Then import and initialize the client with your API key.
SendEmail.php
Sending HTML Emails
To send HTML emails, include thehtml parameter when calling send().
SendEmail.php
You can include the
text parameter to provide both plain text and HTML versions of your email.Sending to Multiple Recipients
You can send emails to multiple recipients and include CC/BCC addresses.SendEmail.php
name and email.
There are limits to the number of recipients you can add to a single request. See our rate limiting guide to learn more.
Including Attachments
You can add attachments by including theattachments parameter in the payload.
SendEmail.php
Email Parameters
Below are the supported parameters for sending emails with the PHP SDK.Managing Webhooks
With the PHP SDK, you can create webhooks, retrieve them, and delete a specific webhook.Creating a New Webhook
Initialize the client and callWebhooks->create() with required parameters url and event.
Webhooks.php
event parameter accepts the following options:
- bounce
- click
- open
- unsubscribe
- complaint
- delivery
Getting All Webhooks
UseWebhooks->get() to view all webhooks you’ve created.
Webhooks.php
Deleting a Webhook
UseWebhooks->delete() with the numeric webhookId.
Deleting a webhook cannot be undone.
Webhooks.php
Webhooks Parameters
The table below contains details about the supported parameters in theWebhooks module.
Retrieving Email Events
You can view all events connected to your API key.Getting All Events
Initialize the client and callEvents->get() to retrieve events.
The
Events->get() method retrieves the top 5 events if no filters are specified.Events.php
Filtering Events
You can filter events by date range, event type, message ID, and pagination options.Events.php
Events Parameters
The table below lists available parameters in theEvents module.
Error Handling
Use try/catch blocks to handle SDK errors. The SDK provides specific exception types for different failure scenarios.SendEmail.php
Exception Types
SendLayerException: Base exception for all SendLayer errorsSendLayerAuthenticationException: Invalid API key or authentication issuesSendLayerValidationException: Invalid parameters or validation errorsSendLayerAPIException: API-specific errors with status code and response data
More Examples
SendLayer PHP SDK
View more details and examples on GitHub.