Download the PHP package naijacloud/email without Composer

On this page you can find all versions of the php package naijacloud/email. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package email

Naijamail — PHP SDK

packagist php dependencies

Quickstart · Sending · Options · Errors · Retries · Webhooks · Laravel · Security

nc-email-php

The official PHP SDK for Naijamail, the transactional email API of Naija Cloud.

Two endpoints, no runtime dependencies, and a webhook verifier.

Quickstart

A successful send() means the message was accepted and queued — it passed authorisation, suppression, reputation and quota checks. It does not mean a mailbox has it. Use get() or a webhook for that.

Requirements

PHP 8.1+ with ext-curl, ext-json and ext-mbstring. Nothing else: this package holds a live sending credential, and every third-party runtime dependency is one more supply chain that can reach it.

PHP 8.2 or newer is recommended. The key is marked #[\SensitiveParameter] wherever it is passed, which keeps it out of exception stack traces (what Sentry and Monolog record); PHP 8.1 ignores that attribute, so on 8.1 set zend.exception_ignore_args=On in production.

Sending

to, cc, bcc and reply_to each take a string or an array of strings.

idempotency_key travels in the Idempotency-Key header only. An empty or blank key is treated as omitted (one is generated); a supplied key is at most 255 bytes of UTF-8 and may not contain CR, LF or NUL.

Attachments take raw bytes. A PHP string is the byte type, so content is always the raw file contents (file_get_contents()), never base64 — the SDK base64-encodes it once on the way out. An empty attachment is refused locally, as the server would refuse it. It will never accept a file path and read it for you — an SDK that opens whatever path it is handed becomes a file-disclosure bug the first time a request-supplied filename reaches it.

Rejected recipients

$sent->rejected is always an array, empty when nobody was refused. A rejection is not a failure — the rest of the message still went out — and re-queueing to a suppressed address is how a sending reputation is lost.

Retrieving a message

$nm->emails->get($id) returns an Email. createdAt and deliveredAt are ?DateTimeImmutable (parsed from the API's ISO 8601 strings; deliveredAt is null until delivery) — the other SDKs use their own language's date type, which is a deliberate difference.

Statuses

queued, sent, delivered, bounced, deferred, complained, rejected, failed — as constants on MessageStatus. A status this release has never seen passes through as a plain string rather than throwing, so a platform change does not break an already-deployed application:

Options

Which key

Two kinds work, and the SDK cannot tell them apart once it has one:

An nc_pat_… platform token is not accepted: those predate the Email send scope and the API refuses them on the mail routes, so the SDK refuses them at construction rather than a request later, with a message saying it is a personal access token and which keys to use instead.

The key comes from the first of: the constructor argument, NAIJAMAIL_API_KEY. Surrounding whitespace (a trailing newline from a secrets file) is trimmed. An absent or malformed key is an exception at construction, not a 401 an hour later in production.

The base URL comes from the base_url option, else NAIJAMAIL_BASE_URL; a blank NAIJAMAIL_BASE_URL counts as unset. A base URL with a query string or fragment is refused. timeout must be greater than zero and max_retries an integer from 0 to 10.

An unknown option is rejected rather than ignored: a silently dropped 'timout' => 5 is a client that waits 30 seconds in production and gives you no way to see why.

Errors

Everything the SDK raises extends NaijamailException, so one catch covers the lot — including the errors raised locally, before a request leaves the process, which carry statusCode === 0.

HTTP Exception Retried
400 ValidationException (NotFoundException when the message is message not found) no
401 AuthenticationException no
403 PermissionException no
404 NotFoundException no
408 TimeoutException yes
409 ConflictException no
422 ValidationException no
any other 4xx (405, 413, 415, 451…) ValidationException no
429 RateLimitException (getRetryAfter()) yes
3xx ServerException ("unexpected redirect") no
5xx ServerException yes
2xx that is not a JSON object, or a send response with no id ServerException ("malformed response") no
DNS / TCP / TLS ConnectionException yes
client-side deadline TimeoutException yes
bad input, caught locally ValidationException no

Every one carries statusCode, errorLabel (the server's short label), requestId (from x-request-id — quote it in a support ticket), the raw response text (getRawBody(), also body/getBody()) and the parsed JSON body (getParsedBody(), null when the body was not a JSON object).

A retrieve for an id that does not exist currently answers 400, not 404. The SDK maps that one case to NotFoundException so you do not have to know.

Retries

Three attempts by default (one try, two retries), 30s per attempt.

Retried: 429, 408, any 5xx, and connection or timeout failures. Never any other 4xx — a 403 on an unverified domain will not verify itself between attempts, and retrying only burns your rate limit.

Backoff is exponential with full jitter (random(0, min(8s, 0.5s * 2^attempt))). Retry-After overrides it on any retried response that carries it (a 429, a 503 during a drain), in either the integer-seconds or HTTP-date form, clamped to 60s so a mis-set header cannot park a worker for an hour. RateLimitException::getRetryAfter() is clamped the same way.

The timeout is a deadline for the whole attempt — connect, upload and the full response — not a per-read timeout. Each retry gets a fresh one.

This is safe because of the idempotency key: if you do not supply one, the SDK generates a UUIDv4 once per send() call and sends it on every attempt of that call. Without it, a timeout followed by a retry mails your customer twice.

Security

The rules this package is held to, all of them tested:

Found a problem? See SECURITY.md. Do not open a public issue.

Laravel

Laravel is the common case in this market, but a separate package would be one more thing to keep in step with the API. Bind the client yourself — it is six lines.

config/services.php:

app/Providers/AppServiceProvider.php:

Then inject it anywhere:

Do not put the client in the session, in a cached job payload, or anywhere else that serializes objects: it will throw, on purpose. Inject it instead.

Webhooks

Live. Naija Cloud delivers these events to endpoints you register, signed exactly as below. Two details this verifier already handles: the timestamp is taken per delivery attempt, so a retry never arrives outside the tolerance window; and during a secret rotation the header carries two v1= values for 24 hours, which is why any match is accepted.

Pass the raw body. json_encode(json_decode($body)) reorders keys and changes spacing, and the signature is over the bytes that were actually sent.

Verification rejects a bad signature, and also a timestamp more than 300 seconds from now — a captured delivery carries a signature that is genuinely ours and would otherwise verify forever. Pass a different $tolerance as the fourth argument; 0 is strict (only the current second passes), and a negative value is a ValidationException. The t= value must be 1–12 digits; the hex signature is compared case-insensitively; and a verified payload that is not a JSON object (an array, a string) is rejected.

Contributing

See CONTRIBUTING.md. The test suite runs offline against a local mock server; there is no way to point it at production.

Licence

MIT. See LICENSE.


All versions of email with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
ext-curl Version *
ext-json Version *
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package naijacloud/email contains the following files

Loading the files please wait ...