> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tryrelaybase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP

> Official PHP SDK for the Relaybase API

Official PHP SDK for Relaybase.

<Card title="GitHub Repository" icon="github" href="https://github.com/Vusion-Labs/relaybase_php_sdk">
  Source, issues, and releases for the Relaybase PHP SDK.
</Card>

## Requirements

* PHP >= 8.1
* cURL extension enabled

## Installation

```bash theme={null}
composer require relaybase/relaybase-php
```

## Authentication

Get your API key from the [Relaybase dashboard](/getting-started/create-api-key) and pass it to the constructor:

```php theme={null}
$client = new Relaybase('rb_key_your_api_key_here');
```

## Usage

### Vanilla PHP

```php theme={null}
<?php

require 'vendor/autoload.php';

use Relaybase\Relaybase;
use Relaybase\EmailMode;
use Relaybase\RelaybaseAPIError;

$client = new Relaybase('rb_key_your_api_key_here');

try {
    $result = $client->verifySingle('test@example.com', EmailMode::Fast);

    echo $result->status;      // valid, invalid, risky
    echo $result->score;       // 0-100
    echo $result->reason;      // human readable reason
    echo $result->suggestion;  // suggested action
} catch (RelaybaseAPIError $e) {
    echo $e->getMessage();
    echo $e->getStatusCode();
}
```

### Laravel

```php theme={null}
<?php

use Relaybase\Relaybase;
use Relaybase\EmailMode;
use Relaybase\RelaybaseAPIError;

$client = new Relaybase(config('services.relaybase.key'));

try {
    $result = $client->verifySingle($request->email, EmailMode::Deep);

    return response()->json($result->toArray());
} catch (RelaybaseAPIError $e) {
    return response()->json(['error' => $e->getMessage()], $e->getStatusCode());
}
```

## Verification modes

| Mode                | Description                             |
| ------------------- | --------------------------------------- |
| `EmailMode::Fast`   | Quick syntax and domain check (default) |
| `EmailMode::Medium` | Includes MX record validation           |
| `EmailMode::Deep`   | Full SMTP verification                  |

See [Validation Results](/concepts/validation-results) for how these map to the API's `mode` field.

## Response fields

`verifySingle()` returns a result object with:

| Field          | Type   | Description                              |
| -------------- | ------ | ---------------------------------------- |
| `status`       | string | `valid`, `invalid`, or `risky`           |
| `score`        | int    | Confidence score 0–100                   |
| `isDisposable` | bool   | Whether the address is disposable        |
| `isFree`       | bool   | Whether it uses a free provider          |
| `isRoleBased`  | bool   | Whether it is a role address             |
| `mxValid`      | bool   | Whether the domain has valid MX records  |
| `syntaxValid`  | bool   | Whether the email syntax is correct      |
| `catchAll`     | bool   | Whether the domain accepts all addresses |
| `smtpCode`     | int    | SMTP response code                       |
| `reason`       | string | Reason for the result                    |
| `suggestion`   | string | Suggested action                         |
| `checkedAt`    | string | Timestamp of the check                   |

## Error handling

Errors from the API are thrown as `RelaybaseAPIError`:

```php theme={null}
try {
    $result = $client->verifySingle('test@example.com', EmailMode::Fast);
} catch (RelaybaseAPIError $e) {
    echo $e->getMessage();
    echo $e->getStatusCode();
}
```

## Roadmap

Bulk validation support for validating multiple emails in a single call is in progress and will be added in a future release.
