1. Go to this page and download the library: Download pyzit/tempmail 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/ */
pyzit / tempmail example snippets
use Pyzit\TempMail\TempMailClient;
$client = new TempMailClient('YOUR_API_TOKEN');
$result = $client->check('[email protected]');
if ($result->isDisposable) {
echo '❌ Disposable email — rejected';
} else {
echo '✅ Looks clean — allowed';
}
> $client = new TempMailClient($_ENV['PYZIT_TOKEN']);
>
use Pyzit\TempMail\TempMailClient;
use Pyzit\TempMail\Exceptions\{
AuthenticationException,
InsufficientScopeError,
QuotaExceededError,
BatchLimitExceededError,
RateLimitException,
ApiException,
TimeoutException,
PyzitException
};
$client = new TempMailClient('YOUR_TOKEN');
try {
$result = $client->check('[email protected]');
} catch (AuthenticationException $e) {
// token is wrong — fail fast, don't retry
die('Check your PYZIT_TOKEN environment variable.');
} catch (InsufficientScopeError $e) {
// token lacks PI too slow — decide how to handle in your app
echo 'Pyzit API timed out — allowing email through.';
} catch (ApiException $e) {
// unexpected server error
echo "Unexpected error {$e->getStatusCode()}: {$e->getResponseBody()}";
} catch (PyzitException $e) {
// fallback for any other SDK error
echo 'Something went wrong with the Pyzit SDK.';
}
function isAllowed(string $email): bool {
try {
return !$client->check($email)->isDisposable;
} catch (PyzitException $e) {
return true; // fail open — let the email through if API is down
}
}
// app/Services/EmailValidator.php
namespace App\Services;
use Pyzit\TempMail\TempMailClient;
use Pyzit\TempMail\Exceptions\PyzitException;
class EmailValidator
{
private TempMailClient $client;
public function __construct()
{
$this->client = new TempMailClient(env('PYZIT_TOKEN'));
}
public function validate(string $email): bool
{
try {
$result = $this->client->check($email);
return !$result->isDisposable;
} catch (PyzitException $e) {
return true; // fail open
}
}
}
// app/Http/Controllers/AuthController.php
public function register(Request $request, EmailValidator $validator)
{
if (!$validator->validate($request->email)) {
return response()->json([
'error' => 'Disposable email addresses are not allowed.'
], 422);
}
// continue with registration...
}
// src/Validator/NotDisposableEmail.php
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Pyzit\TempMail\TempMailClient;
use Pyzit\TempMail\Exceptions\PyzitException;
class NotDisposableEmailValidator extends ConstraintValidator
{
private TempMailClient $client;
public function __construct()
{
$this->client = new TempMailClient($_ENV['PYZIT_TOKEN']);
}
public function validate($value, Constraint $constraint): void
{
try {
$result = $this->client->check((string)$value);
if ($result->isDisposable) {
$this->context->buildViolation('Disposable emails are not allowed.')
->addViolation();
}
} catch (PyzitException $e) {
// fail open if API is unreachable
}
}
}
// src/Validator/NotDisposableEmail.php (constraint class)
namespace App\Validator;
use Symfony\Component\Validator\Constraint;
#[\Attribute]
class NotDisposableEmail extends Constraint
{
public string $message = 'Disposable email addresses are not allowed.';
}
// functions.php
ail\TempMailClient;
use Pyzit\TempMail\Exceptions\PyzitException;
function validate_disposable_email($email) {
$client = new TempMailClient(getenv('PYZIT_TOKEN'));
try {
$result = $client->check($email);
return !$result->isDisposable;
} catch (PyzitException $e) {
return true; // fail open
}
}
add_filter('registration_errors', function($errors, $sanitized_user_login, $user_email) {
if (!validate_disposable_email($user_email)) {
$errors->add('disposable_email', 'Disposable email addresses are not allowed.');
}
return $errors;
}, 10, 3);