Download the PHP package sendlayer/sendlayer-php without Composer
On this page you can find all versions of the php package sendlayer/sendlayer-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sendlayer/sendlayer-php
More information about sendlayer/sendlayer-php
Files in sendlayer/sendlayer-php
Package sendlayer-php
Short Description Official PHP SDK for SendLayer API
License MIT
Informations about the package sendlayer-php
SendLayer PHP SDK
The official PHP SDK for interacting with the SendLayer API, providing a simple and intuitive interface for sending emails, managing webhooks, and retrieving email events.
Features
- Email Sending: Send transactional emails with support for HTML, text, attachments, and advanced options
- Webhook Management: Create, retrieve, and delete webhooks for real-time event notifications
- Event Tracking: Retrieve email events and analytics data
- Error Handling: Comprehensive exception handling with specific error types
- Validation: Built-in validation for email addresses, URLs, and API parameters
- File Attachments: Support for both local and remote file attachments
- Modern PHP: Built with PHP 7.4+ features and PSR-4 autoloading
Installation
Using Composer (Recommended)
Manual Installation
- Download the SDK
- Include the autoloader in your project
- Install dependencies:
composer install
Quick Start
Configuration (Optional)
You can pass additional configuration options when initializing the SDK:
Email Sending
Basic Email
HTML Email
HTML Email with Plain-Text Fallback
Pass both html and text to send a message that carries an HTML part for
clients that render it and a plain-text alternative for those that don't.
Recommended for deliverability.
Both parts are sent; ContentType is reported to the API as HTML whenever an
HTML body is present, and as Text when only text is supplied.
Email with Sender Name
Multiple Recipients
Email with CC and BCC
Email with Attachments
Email with Custom Headers and Tags
Webhook Management
Create a Webhook
Get All Webhooks
Delete a Webhook
Event Tracking
Get All Events
Get Events with Filters
Get Events for Specific Message
Error Handling
The SDK provides specific exception types for different error scenarios:
When the API returns errors, the SDK preserves them on the exception's $errors
property as the raw Errors entries from the response (each with a numeric Code
and a Message):
$errors is declared on the base SendLayerException, so it is available on
every exception type. It is an empty array when the SDK raises the error locally
(client-side validation, connection failures) and when the API returns a body
that isn't the JSON Errors shape, so guard with empty($e->errors) before
relying on it.
getMessage() returns the API's message text verbatim for the specific exception
types listed below, joining multiple messages with ;. The one exception is
SendLayerAPIException, which prefixes its message with API Error {status}:.
When the response body isn't JSON, the message falls back to the HTTP reason
phrase (e.g. Bad Request).
The numeric Code values are a fixed set defined by the API — see the
SendLayer error codes reference
for the full table (14 = recipient suppressed, 17 = email quota reached,
32 = domain not activated, and so on).
Exception Types
SendLayerException: Base exception for all SendLayer errorsSendLayerAuthenticationException: Invalid API key or authentication issuesSendLayerValidationException: Invalid parameters or validation errorsSendLayerAPIException: any status not covered by the types above, exposing the public$statusCode(int) and$response(array, the decoded response body)SendLayerNotFoundException: Resource not found (404 errors)SendLayerRateLimitException: Rate limit exceeded (429 errors)SendLayerInternalServerException: Internal server error (500 responses only; other 5xx statuses raiseSendLayerAPIException)
getCode() carries the HTTP status code of the response, with one caveat: a 422
response raises a SendLayerValidationException whose code is 400, since both
statuses map to that type. Match on the exception class, or on the Code values
in $errors, rather than on getCode() when you need to tell them apart.
Supported Events
Webhook Events
bounce: Email bouncedclick: Link was clickedopen: Email was openedunsubscribe: User unsubscribedcomplaint: User marked as spamdelivery: Email was delivered
Event Tracking Events
accepted: Email was accepted by the serverrejected: Email was rejecteddelivered: Email was deliveredopened: Email was openedclicked: Link was clickedunsubscribed: User unsubscribedcomplained: User marked as spamfailed: Email delivery failed
Requirements
- PHP 7.4 or higher
- Guzzle HTTP Client 7.x or 8.x
- JSON extension
- cURL extension (recommended)
License
This SDK is licensed under the MIT License. See the LICENSE file for details.
Support
For support, please contact:
- Email: [email protected]
- Documentation: https://developers.sendlayer.com
- GitHub Issues: https://github.com/sendlayer/sendlayer-php/issues
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Changelog
See CHANGELOG.md for a list of changes and version history.