Download the PHP package rnevarezc/postal without Composer
On this page you can find all versions of the php package rnevarezc/postal. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package postal
Postal API Client
This library helps you use the Postal API in PHP 7.2 (and above) to send Emails, get Message Details & Deliveries and Implement Events to handle Server Webhooks.
It uses GuzzleHTTP client and PSR-7: HTTP-PSR7 interfaces.
Installation
Install the library using Composer:
Usage
Using the Client
You will need an API Credential from your Postal Installation to use the API Client.
Sending an Email
Sending an email is simple. You can follow the example below:
Or Create a new mail message and add manually each of the Mail attributes
If you'd like to capture the Messages Dispatched for each recipient of the Mail. You can do it like so:
Getting Message Details
You can get the Details of a Message using the Client. You just need the Message ID
Getting Message Deliveries
You can get the Deliveries of a Message using the Client. You just need the Message ID
Events and Webhooks!
This library provides support for all the type of Payloads that a Postal Installation can send via Webhooks.
You must configure your postal Installation to send those events to an URL of your choice to be able to use this library.
You can get more information about Webhooks and Payloads in the Postal Documentation
Message Status Events, Bounces & Click Events
Message Status events all receive the same payload (with different data) based on the status of a message.
-
- when a message is successfully delivered
-
- when a message's delivery has been delayed.
-
- when a message cannot be delivered.
-
- when a message is held.
-
If a message bounces, you'll receive the event.
- If you have click tracking enabled, the event will tell you that a user has clicked on a link in one of your e-mails.
The Class is a Factory that can Parse a Payload of any of these events and build the correct Event Implementation.
Capturing these Events in an Handler (or a Controller) is very easy. You could define a Class in your app and capture the request like this:
If you capture the POST payload in any other way you could send that payload to the Factory directly to build an Event:
If a invalid Payload is provided, an is thrown
Using the .
Depending on the Event Type you get an Concrete Implementation of the . The defined types (and their clases) are the same provided by Postal:
- : Returns an instance of the associated associated to the event.
- : Returns the type of the Event.
- : Returns an array representation of the Event.
MessageBounced Event:
- : Returns an instance of with the Bounced Message.
Server Events
If you'd like to capture a event you can use that specific Event Class:
The same way, if you'd like to capture any kind of SendLimit Event, you can do it via the Static Methods defined in the Factory Class:
or
The $event variable will have the correct Event depending on the Payload.
It is strongly recommended to use different Handlers (or Controllers) by type of Event and don't use a Common webhook URL to handle them all!
API Information
You can get more information about the Postal API and Payloads in the Postal Project Wiki