Back to Docs

Php SDK

Official MailPass SDK for Php

Installation

composer require mailpass/mailpass-php

Quick Start — OTP Send & Verify

<?php
use MailPass\Client;

$client = new Client('mp_live_your_api_key_here');

// Send OTP
$response = $client->otp->send([
    'email' => 'user@example.com',
    'purpose' => 'login',
]);
echo $response['request_id'];

// Verify OTP
$result = $client->otp->verify([
    'request_id' => $response['request_id'],
    'otp' => '123456',
]);

if ($result['success']) {
    echo 'Verified! ' . $result['email'];
}

Subscribers — List & Create

// List subscribers
$subscribers = $client->subscribers->list([
    'list_id' => 1,
    'page' => 1,
    'per_page' => 20,
]);
foreach ($subscribers['data'] as $sub) {
    echo $sub['email'] . ' ' . $sub['status'] . "\n";
}

// Create subscriber
$newSub = $client->subscribers->create([
    'email' => 'new@example.com',
    'name' => 'Jane Doe',
    'list_id' => 1,
    'tags' => ['newsletter'],
    'double_optin' => true,
]);
echo $newSub['data']['uuid'];

Error Handling

use MailPass\Exception\ApiException;
use MailPass\Exception\ValidationException;
use MailPass\Exception\RateLimitException;

try {
    $response = $client->otp->send(['email' => 'user@example.com']);
} catch (ValidationException $e) {
    echo "Validation: " . $e->getMessage() . "\n";
    print_r($e->getDetails());
} catch (RateLimitException $e) {
    echo "Rate limited. Retry after " . $e->getRetryAfter() . "s\n";
} catch (ApiException $e) {
    echo "API error [{$e->getErrorCode()}]: {$e->getMessage()}\n";
}

For the full API reference, see the API Documentation or the interactive Swagger UI.

Usamos cookies

Usamos cookies para mejorar su experiencia. Puede elegir qué categorías de cookies permitir. Más información