Download the PHP package mailhive/mailhive-php without Composer
On this page you can find all versions of the php package mailhive/mailhive-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mailhive/mailhive-php
More information about mailhive/mailhive-php
Files in mailhive/mailhive-php
Package mailhive-php
Short Description The official PHP SDK for Mailhive Send, with a Laravel mail transport.
License MIT
Homepage https://mailhive.africa/docs/sdks/php
Informations about the package mailhive-php
mailhive/mailhive-php
The official PHP SDK for Mailhive Send. It needs PHP 8.1+ and only ext-curl and ext-json. It includes a Laravel mail driver.
Send an email
The keys match the API reference exactly: cc, bcc, reply_to, headers, tags, template_id, variables and attachments.
An attachment's content is the raw file, which is encoded for you. Use content_base64 if your data is already base64:
The accepted email's rejected maps any address dropped before sending to why it can't work (domain_typo, domain_not_found, no_mail_server, invalid_syntax); such addresses never bounce.
Check addresses before sending
Run the same checks on a form, while the person can still fix the typo. Nothing is sent or stored:
Audiences and contacts
With an API key that has Full access, keep an audience in step with your app or CRM:
upsert adds the person, or updates them if they're already there, so it's safe to repeat. Other calls: audiences->list, audiences->create, audiences->rename, contacts->list (pass ['email' => …] to find one person), contacts->add, contacts->upsertBatch (up to 100; check each result's ok), contacts->get, contacts->update, contacts->unsubscribe and contacts->delete.
Someone who unsubscribed, or reported your email as spam, can't be subscribed again by your code: you get a ConflictException with code contact_unsubscribed. To bring them back, ask them to confirm:
They're pending, and never mailed by a broadcast, until they click the link. See the contacts API reference.
Laravel
The package registers itself. Add the key and the mailer:
Every Mailable and notification then sends through Mailhive, including attachments, cc, bcc and Reply-To. A Mailable's tags and metadata become Mailhive tags. To make a send safe to repeat, add an X-Mailhive-Idempotency-Key header:
You can also type-hint the client anywhere: public function __construct(private \Mailhive\Mailhive $mailhive) {}.
Plain Symfony apps can use new \Mailhive\Laravel\MailhiveTransport($client) as a Symfony Mailer transport.
Retries and idempotency
Every send carries an Idempotency-Key. Retries reuse it, so a retry never sends twice.
- Retried (up to 2 times, then configurable): network errors, timeouts, 5xx responses, and
429 rate_limitedafter theRetry-Afterdelay. - Not retried: a used-up allowance and invalid requests.
To stay safe across restarts, pass your own key:
Errors
| Exception | Status |
|---|---|
AuthenticationException |
401 |
BillingException |
402 |
PermissionException |
403 |
NotFoundException |
404 |
ConflictException |
409 |
ValidationException |
422 |
RateLimitException |
429 |
ApiException |
other statuses, and the base class of all of the above |
ConnectionException |
no response |
All of them extend MailhiveException. Use errorCode() for Mailhive's code: PHP reserves getCode() for the HTTP status.
Webhooks
Options
Test keys (mhs_test_…) work unchanged: delivery is simulated and nothing is billed.
This package is published from the mailhive-sdks monorepo. Please open issues and pull requests there.
Releasing (maintainers)
- Bump
Mailhive::VERSION, then merge tomainin mailhive-sdks. - Push the tag
php-vX.Y.Zthere. - The
split-phpworkflow mirrorsphp/to Naszat/mailhive-php and tags itvX.Y.Z. Packagist then picks it up.
Without the PHP_MIRROR_DEPLOY_KEY secret, run the same steps from a checkout of main:
All versions of mailhive-php with dependencies
ext-curl Version *
ext-json Version *