Download the PHP package mailcapture/mailcapture-php without Composer
On this page you can find all versions of the php package mailcapture/mailcapture-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mailcapture/mailcapture-php
More information about mailcapture/mailcapture-php
Files in mailcapture/mailcapture-php
Package mailcapture-php
Short Description Official PHP SDK for the MailCapture email testing API
License MIT
Homepage https://mailcapture.app
Informations about the package mailcapture-php
mailcapture-php
Official PHP SDK for MailCapture — a real email capture API for integration testing OTP codes, verification links, and other transactional emails.
MailCapture captures emails sent by your application during testing. Give each test a unique address, trigger your email flow, then use this SDK to retrieve and assert on what arrived — subject lines, body text, OTP codes, and more. Works with PHPUnit, Pest, or any other PHP test framework.
A MailCapture account is required — free and paid plans are available. Sign up at mailcapture.app.
Requirements
- PHP 8.1+
- Guzzle 7 (
guzzlehttp/guzzle)
Installation
Quick start
The pattern for integration tests
API reference
new MailCapture($apiKey, ...)
ping() → PingResult
Validates your API key and returns your address template. Caches your username so address() works without a network call.
waitFor(tag, timeout, pollTimeout, after) → Capture
Long-polls the API and returns the first email captured for the given tag. The server holds the connection open — no busy-waiting.
Throws MailCaptureTimeoutException if no email arrives in time.
inbox(tag) → Inbox
Returns a scoped Inbox for a tag. Keeps test code clean.
address(tag) → string
Generates the capture email address synchronously. Requires ping() first (or username in the constructor).
list(tag, limit, after) → CaptureList
Lists recent captures (newest first).
get(captureId) → Capture
Get a single capture by ID. Throws MailCaptureNotFoundException if not found.
delete(tag) → void
Deletes all captures for a tag. Use in setUp() for test isolation.
The Capture object
The otp field is extracted automatically. If your OTP is embedded in a sentence, the service finds it for you.
Exception handling
All exceptions extend MailCaptureException extends \RuntimeException and have getErrorCode().
| Exception | getErrorCode() |
When |
|---|---|---|
MailCaptureAuthException |
UNAUTHORIZED |
Invalid or revoked API key |
MailCaptureTimeoutException |
TIMEOUT |
waitFor exceeded timeout |
MailCaptureNotFoundException |
NOT_FOUND |
get() — capture not found |
MailCaptureNetworkException |
NETWORK_ERROR |
Could not reach the API |
MailCaptureApiException |
varies | Unexpected API error |
Testing with a mock HTTP client
Inject a Guzzle mock client to test your code without hitting the real API: