PHP code example of temp-mail-io / temp-mail-php

1. Go to this page and download the library: Download temp-mail-io/temp-mail-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

temp-mail-io / temp-mail-php example snippets



$emailClient = \TempMailIo\TempMailPhp\Factory::createEmailClient('YOUR_API_KEY');

$createResponse = $emailClient->create();

if ($createResponse->errorResponse !== null) {
    echo "Code: " . $response->errorResponse->error->code . PHP_EOL;
    echo "Detail: " . $response->errorResponse->error->detail . PHP_EOL;
    echo "Type: " . $response->errorResponse->error->type . PHP_EOL;
    exit;
}

// Use the created temporary email on the website, service, etc...

$messagesResponse = $emailClient->getMessages($createResponse->successResponse->email);

if ($messagesResponse->errorResponse !== null) {
    echo "Code: " . $messagesResponse->errorResponse->error->code . PHP_EOL;
    echo "Detail: " . $messagesResponse->errorResponse->error->detail . PHP_EOL;
    echo "Type: " . $messagesResponse->errorResponse->error->type . PHP_EOL;
    exit;
}

foreach ($messagesResponse->successResponse->messages as $message) {
    // Iterate over messages
}

$response = \TempMailIo\TempMailPhp\Factory::createDomainClient('YOUR_API_KEY')->getAvailableDomains();

if ($response->errorResponse !== null) {
    // handle error
}

foreach ($response->successResponse->domains as $domain) {
    // Iterate over domains
}

$response = \TempMailIo\TempMailPhp\Factory::createRateLimitClient('YOUR_API_KEY')->getStatus();

if ($response->errorResponse !== null) {
    // handle error
}

echo "Rate limit: " . $response->successResponse->limit . PHP_EOL;
echo "Remaining limit: " . $response->successResponse->remaining . PHP_EOL;
echo "Used limit: " . $response->successResponse->used . PHP_EOL;
echo "Reset limit: " . $response->successResponse->reset . PHP_EOL;

$response = \TempMailIo\TempMailPhp\Factory::createEmailClient('YOUR_API_KEY')->create();

if ($response->errorResponse !== null) {
    // handle error
}

echo "Rate limit: " . $response->successResponse->rateLimit->limit . PHP_EOL;
echo "Remaining limit: " . $response->successResponse->rateLimit->remaining . PHP_EOL;
echo "Used limit: " . $response->successResponse->rateLimit->used . PHP_EOL;
echo "Reset limit: " . $response->successResponse->rateLimit->reset . PHP_EOL;

$response = \TempMailIo\TempMailPhp\Factory::createEmailClient('YOUR_API_KEY')->create();

if ($response->errorResponse !== null) {
    // handle error
}

echo "Email: " . $response->successResponse->email . PHP_EOL;

$emailClient = \TempMailIo\TempMailPhp\Factory::createEmailClient('YOUR_API_KEY');

$response = $emailClient->getMessages('[email protected]');

if ($response->errorResponse !== null) {
    // handle error
}

foreach ($response->successResponse->messages as $message) {
    // Iterate over messages
}

$messageClient = \TempMailIo\TempMailPhp\Factory::createMessageClient('YOUR_API_KEY');

$deleteResponse = $messageClient->delete($response->successResponse->messages[0]->id);

if ($deleteResponse->errorResponse !== null) {
    // handle error
}