truelist/truelist-php
Composer 安装命令:
composer require truelist/truelist-php
包简介
PHP SDK for the Truelist email validation API
README 文档
README
PHP SDK for the Truelist email validation API.
Requirements
- PHP 8.1+
- Guzzle 7.0+
Start free — 100 validations + 10 enhanced credits, no credit card required. Get your API key →
Installation
composer require truelist/truelist-php
Quick Start
use Truelist\Truelist; $client = new Truelist('your-api-key'); $result = $client->validate('user@example.com'); if ($result->isValid()) { echo "Email is valid!"; }
Configuration
$client = new Truelist('your-api-key', [ 'base_url' => 'https://api.truelist.io', // API base URL 'timeout' => 10, // Request timeout in seconds 'max_retries' => 2, // Retries on 429/5xx errors 'raise_on_error' => false, // Throw on transient errors ]);
| Option | Default | Description |
|---|---|---|
base_url |
https://api.truelist.io |
API base URL |
timeout |
10 |
Request timeout in seconds |
max_retries |
2 |
Number of retries on 429/5xx errors (with exponential backoff) |
raise_on_error |
false |
When false, transient errors return an unknown result. When true, they throw. |
Methods
validate(string $email): ValidationResult
Validates an email address. Sends a POST to /api/v1/verify_inline with the email as a query parameter.
$result = $client->validate('user@example.com'); $result->email; // 'user@example.com' $result->state; // 'ok', 'email_invalid', 'accept_all', 'unknown' $result->subState; // 'email_ok', 'is_disposable', 'is_role', etc. $result->suggestion; // Suggested correction or null $result->domain; // 'example.com' $result->canonical; // 'user' $result->mxRecord; // MX record or null $result->firstName; // First name or null $result->lastName; // Last name or null $result->verifiedAt; // ISO 8601 timestamp or null
account(): AccountInfo
Retrieves account information from GET /me.
$account = $client->account(); $account->email; // 'team@company.com' $account->name; // 'Team Lead' $account->uuid; // 'a3828d19-...' $account->timeZone; // 'America/New_York' $account->isAdminRole; // true $account->accountName; // 'Company Inc' $account->paymentPlan; // 'pro'
Result Predicates
$result = $client->validate('user@example.com'); // State checks $result->isValid(); // true if state is 'ok' $result->isInvalid(); // true if state is 'email_invalid' $result->isAcceptAll(); // true if state is 'accept_all' $result->isUnknown(); // true if state is 'unknown' $result->isError(); // true if result came from a transient error // Sub-state checks $result->isRole(); // true if sub-state is 'is_role' $result->isDisposable(); // true if sub-state is 'is_disposable'
Response States
| State | Description |
|---|---|
ok |
Email is valid and deliverable |
email_invalid |
Email is not deliverable |
accept_all |
Domain accepts all emails (catch-all) |
unknown |
Could not determine validity |
Response Sub-States
| Sub-State | Description |
|---|---|
email_ok |
Email is valid |
is_disposable |
Disposable/temporary email |
is_role |
Role-based address (info@, admin@) |
failed_smtp_check |
SMTP check failed |
unknown_error |
Could not determine |
Error Handling
The SDK uses a hierarchy of exceptions:
TruelistException-- base exceptionAuthenticationException-- invalid API key (401). Always thrown, never suppressed.RateLimitException-- rate limit exceeded (429)ApiException-- server errors (5xx), connection errors
Auth Errors Always Throw
Authentication errors (HTTP 401) always throw an AuthenticationException, regardless of the raise_on_error setting.
use Truelist\Exceptions\AuthenticationException; try { $result = $client->validate('user@example.com'); } catch (AuthenticationException $e) { // Invalid API key - always thrown }
Transient Error Behavior
For transient errors (429, 5xx, timeouts), behavior depends on raise_on_error:
// raise_on_error: false (default) // Returns a ValidationResult with state='unknown' and error=true $result = $client->validate('user@example.com'); if ($result->isError()) { // Handle transient failure gracefully } // raise_on_error: true // Throws RateLimitException or ApiException $client = new Truelist('key', ['raise_on_error' => true]); try { $result = $client->validate('user@example.com'); } catch (RateLimitException $e) { // 429 } catch (ApiException $e) { // 5xx or connection error }
Retry Behavior
The SDK automatically retries on 429 and 5xx errors with exponential backoff. Configure with max_retries (default: 2). Auth errors (401) are never retried.
Testing
composer install vendor/bin/phpunit
Getting Started
Sign up for a free Truelist account to get your API key. The free plan includes 100 validations and 10 enhanced credits — no credit card required.
License
MIT
truelist/truelist-php 适用场景与选型建议
truelist/truelist-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「validation」 「email-verification」 「truelist」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 truelist/truelist-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 truelist/truelist-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 truelist/truelist-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Email-Guard core library for PHP: local email checks (syntax, reserved TLDs, disposable domains) plus optional escalation to the EmailSherlock Verify API.
AbstractEmailValidation - Wrapper to quickly start using the powerful AbstractAPI's email validation service in your projects.
Adds request-parameter validation to the SLIM 3.x PHP framework
Symfony integration for Email-Guard: a VerifiedEmail constraint and a verify_email form option that block disposable and undeliverable addresses at submit time.
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-08