Download the PHP package paubox/paubox-php without Composer
On this page you can find all versions of the php package paubox/paubox-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download paubox/paubox-php
More information about paubox/paubox-php
Files in paubox/paubox-php
Package paubox-php
Short Description A PHP package for the Paubox Transactional Email API
License Apache-2.0
Homepage https://github.com/Paubox/paubox-php
Informations about the package paubox-php
Paubox PHP
NEW: Version 2 of the Paubox Email API SDK for PHP is available to beta test now. It includes code for newer features like bulk message sending, dynamic templates, and more. We will be deprecating the old in the near future.
This is the official PHP wrapper for the Paubox Email API.
The Paubox Email API allows your application to send secure, HIPAA compliant email via Paubox and track deliveries and opens. The API wrapper also allows you to construct and send messages.
Table of Contents
- Installation
- Usage
- Sending messages
- Allowing non-TLS message delivery
- Forcing Secure Notifications
- Adding Attachments and Additional Headers
- Checking Email Dispositions
- Paubox Forms
- Getting a form
- Submitting a form
- Submitting a form with file attachments
- Scoped API keys
- Getting a form by ID
- Listing forms
- Creating a form
- Updating a form
- Archiving and unarchiving a form
- Copying a form
- Form statistics
- Listing submissions
- Downloading submissions as CSV
- Downloading a submission as PDF
- Error handling
- Requirements
- Webhooks
- Creating a webhook endpoint
- Listing webhook endpoints
- Getting a webhook endpoint
- Updating a webhook endpoint
- Deleting a webhook endpoint
- Webhook error handling
- Running the tests
- Contributing
- License
Installation
Using composer:
Getting Paubox API Credentials
You will need to have a Paubox account. You can sign up here.
Once you have an account, follow the instructions on the Rest API dashboard to verify domain ownership and generate API credentials.
Configuring API Credentials
Include your API credentials in your environment file.
Usage
To send email, prepare a Message object and call the sendMessage method of Paubox.
Sending messages
Allowing non-TLS message delivery
If you want to send non-PHI mail that does not need to be HIPAA-compliant, you can allow the message delivery to take place even if a TLS connection is unavailable.
This means the message will not be converted into a secure portal message when a non-TLS connection is encountered. To allow a non-TLS message delivery, call the setAllowNonTLS(true) method on the message object.
Forcing Secure Notifications
Paubox Secure Notifications allow an extra layer of security, especially when coupled with an organization's requirement for message recipients to use 2-factor authentication to read messages (this setting is available to org administrators in the Paubox Admin Panel).
Instead of receiving an email with the message contents, the recipient will receive a notification email that they have a new message in Paubox.
Adding Attachments and Additional Headers
Checking Email Dispositions
The SOURCE_TRACKING_ID of a message is returned in the response of the sendMessage method. To check the status for any email, use its source tracking id and call the getEmailDisposition method of Paubox:
Paubox Forms
PauboxForms provides access to the Paubox Forms API. The public endpoints — getting a form definition and submitting a form response — are unauthenticated and need no credentials. The form-management endpoints (listing, creating, updating, archiving, and copying forms, plus retrieving submissions, stats, CSVs, and PDFs) require a scoped API key — see Scoped API keys below.
Getting a form
Retrieve the full definition of a form (HTML, JSON schema, CSS, and metadata) by its UUID.
Submitting a form
Build a FormSubmission with form_data matching the form's field schema and call submitForm. Returns true on success; throws an exception on failure.
Submitting a form with file attachments
Attachments must be base64-encoded. Maximum total request size is 250 MB.
Scoped API keys
All of the form-management methods below require a Paubox scoped API key with the forms scope. Generate one from your Paubox dashboard, then either pass it to the PauboxForms constructor or set it in the PAUBOX_FORMS_API_KEY environment variable. The SDK sends it as an Authorization: Bearer header.
Important: PAUBOX_FORMS_API_KEY is a different credential from the transactional Email API key (PAUBOX_API_KEY). Do not reuse the same value for both — although both are sent as Authorization: Bearer headers to the same host, they are scoped to different APIs: the email client sends PAUBOX_API_KEY to https://api.paubox.com/v1/email, while PauboxForms sends PAUBOX_FORMS_API_KEY to https://api.paubox.com/v1/forms. Mixing them misdelivers a credential to the wrong endpoint. Configure both independently:
Optionally, override the target endpoint with a constructor argument or the PAUBOX_FORMS_BASE_URL environment variable. Defaults to https://api.paubox.com/v1/forms:
If no key is configured, calling a management method throws a Paubox\Forms\PauboxFormsException. The public getForm and submitForm methods never require a key.
Error handling
All Forms methods throw Paubox\Forms\PauboxFormsException on failure. The exception's message contains the operation and HTTP status only — the raw response body is not included in the message (form submission bodies can contain PHI). Read getStatusCode(), getUrl(), and getResponseBody() explicitly if you need the details:
Requirements
- PHP 8.1 or newer (older versions cannot install because of an unrelated advisory on the vendored HTTP client).
- The package pins its HTTP dependency (
nategood/httpful ^1.0) and enables strict TLS certificate verification.
Getting a form by ID
Retrieve a form through the authenticated management endpoint. Unlike the public getForm, this also returns inactive and archived forms.
Listing forms
List your forms with optional filtering, searching, ordering, and pagination. Include customer_id (your Paubox customer ID) — the API rejects list requests that don't name the customer the key belongs to. Booleans are handled for you — pass real true/false values.
Creating a form
Build a Forms\Form and call createForm. title, formJson, and customerId are required; the other setters are optional. Returns the new form's UUID.
Updating a form
Partial update — pass an associative array with only the attributes you want to change. Allowed keys: title, description, form_json, vanity_url, recipient, active, subscription_list_id. Omitted keys are left unchanged.
Archiving and unarchiving a form
Both return true on success and throw an exception on failure.
Copying a form
Duplicate an existing form under a new title. Returns the full new form object.
Form statistics
Get aggregate stats for your forms. customer_id is optional and defaults to the customer associated with your API key.
Listing submissions
List the submissions for a form with optional ordering and pagination.
Downloading submissions as CSV
getSubmissionsCsv returns every submission for a form as a CSV string; getSubmissionCsv returns a single submission. Save the result to a file or process it directly.
Downloading a submission as PDF
Returns the PDF as a binary string — write it straight to a file.
Webhooks
A webhook endpoint is a URL you own that Paubox notifies when something happens. PauboxWebhooks
manages those subscriptions: which URL to notify, and for which events.
Construct it with a scoped API key, sent as Authorization: Bearer <key>. The key can also
come from the PAUBOX_WEBHOOKS_API_KEY environment variable:
Which events a key may subscribe to follows from its scopes. The SDK does not inspect them — the service refuses an event the key isn't scoped for with 403, and an unrecognised event with 422.
Available events
| Event | Fires when |
|---|---|
forms.submission.created |
A form submission is received |
api_mail_log_delivered |
An Email API message is delivered |
api_mail_log_opened |
A delivered message is opened |
api_mail_log_temporary_failure |
Delivery fails temporarily |
api_mail_log_permanent_failure |
Delivery fails permanently |
email.inbound.received |
Inbound mail is received |
The four Email API events keep their legacy api_mail_log_ names, so a receiver written
against the old Email API webhooks keeps working unchanged. Note these are the names on
the wire: delivered or failed on their own are rejected as unknown.
The SDK does not check these names. The catalog lives in the service, so an event added later works here without upgrading the SDK.
Creating a webhook endpoint
signing_secret is returned once, here. It is not on getWebhookEndpoint or
listWebhookEndpoints, and there is no way to read it back — recovering from a lost secret means
deleting the endpoint and creating a new one. Use it to verify that deliveries really came from
Paubox.
Listing webhook endpoints
Pass page and items to paginate:
Getting a webhook endpoint
Updating a webhook endpoint
Only the keys you pass are sent, so changing the status leaves the URL and events alone:
Pausing deliveries without losing the subscription is what disabled is for; set active to
resume. Passing events replaces the list rather than adding to it.
Deleting a webhook endpoint
Returns true — the service answers 204 No Content. Deleting stops every event on that
endpoint, and the signing secret goes with it.
Webhook error handling
A non-2xx response throws Paubox\Webhooks\PauboxWebhooksException. The service's own message is
promoted onto the exception message, since a bare status says nothing about which field was wrong;
the raw body is on getResponseBody():
Two cases worth handling explicitly: subscribing a target_url that already has an endpoint comes
back as 422, and an id that doesn't belong to your account is a 404 rather than a 403. An id that
isn't a UUID is rejected locally, before any request is made.
Running the tests
The default test suite is offline and read-only. Requires no credentials, no fixtures, no network:
Tests that hit the network or write to a real customer account are separated into groups and excluded by default:
network— read-only tests that resolve a real API endpoint (e.g. the publicgetForm404 path).mutating— creates, copies, archives, updates, or submits against a real customer. Restores state where possible (try/finally), but should never run against a production customer without explicit intent.
To run them:
:warning: The mutating group writes to whatever host
PAUBOX_FORMS_BASE_URLpoints at (defaults to production). Every test attempts to restore state in afinallyblock, but a crash between an archive and a restore leaves the form archived — verify the test customer is a QA account before running.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/paubox/paubox-php.
License
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright
Copyright © 2021, Paubox, Inc.
💬 Community & support
Questions, ideas, or want to share what you built? Join the Paubox Community — the single home for discussions across every Paubox SDK and API.
🔐 Found a security issue? Email [email protected] — please don't post it publicly.