evilmail/evilmail-php
Composer 安装命令:
composer require evilmail/evilmail-php
包简介
Official PHP SDK for the EvilMail API
关键字:
README 文档
README
EvilMail PHP SDK
Official PHP client library for the EvilMail disposable email API
Installation • Quick Start • API Reference • Error Handling • Documentation
The EvilMail PHP SDK provides a clean, type-safe interface for integrating temporary email, disposable email addresses, email verification, inbox management, and custom domain email services into your PHP applications. Built for PHP 8.1+ with full PSR-12 compliance.
Features
- Temporary Email — Create anonymous disposable email addresses with configurable TTL
- Email Verification Codes — Automatically extract OTP codes from Google, Facebook, Instagram, TikTok, Discord, Twitter, LinkedIn, iCloud
- Account Management — Create, delete, and manage persistent email accounts on custom domains
- Inbox Access — Read emails, list messages, fetch full message content (HTML & plain text)
- Random Email Generator — Batch create random email accounts with auto-generated passwords
- Domain Management — List free, premium, and custom email domains
- Shortlink Creation — Generate short URLs for temporary email sessions
- Temp Email Messages — Read individual messages from temporary email sessions
- Typed Exceptions — Granular error handling with dedicated exception classes
- Guzzle Powered — Built on Guzzle HTTP for reliable, configurable HTTP transport
Requirements
- PHP 8.1 or later
- Guzzle 7.5+
- An EvilMail API key — Get yours free
Installation
Install via Composer:
composer require evilmail/evilmail-php
Quick Start
<?php require 'vendor/autoload.php'; use EvilMail\Client; $client = new Client('your-api-key'); // Create a temporary disposable email address $temp = $client->tempEmail->create('evilmail.pro', 60); echo "Temporary email: " . $temp['email'] . "\n"; echo "Session token: " . $temp['sessionToken'] . "\n"; // Check session status and retrieve messages $session = $client->tempEmail->getSession($temp['sessionToken']); echo "Expires at: " . $session['expiresAt'] . "\n"; // Read a specific message from temp email inbox $message = $client->messages->read($temp['sessionToken'], 1); echo "Subject: " . $message['subject'] . "\n"; // Extract a Google verification code from any email $code = $client->verification->getCode('google', 'user@yourdomain.com'); echo "Verification code: " . $code['code'] . "\n"; // List all email accounts $accounts = $client->accounts->list(); // Batch create random email accounts $batch = $client->randomEmail->create('yourdomain.com', 5, 16); echo "Created " . $batch['count'] . " random accounts\n";
Configuration
// Basic initialization $client = new Client('your-api-key'); // Custom base URL (self-hosted instances) $client = new Client('your-api-key', 'https://your-instance.example.com'); // Advanced Guzzle configuration (proxy, timeout, SSL) $client = new Client('your-api-key', null, [ 'timeout' => 60, 'proxy' => 'tcp://localhost:8080', 'verify' => '/path/to/ca-bundle.crt', ]);
API Reference
Temporary Email
Create anonymous, disposable email addresses with automatic expiration. Perfect for sign-up verification, testing, and privacy protection.
Create Temporary Email
$temp = $client->tempEmail->create(?string $domain, ?int $ttlMinutes);
| Parameter | Type | Required | Description |
|---|---|---|---|
$domain |
string|null |
No | Domain for the temporary email address |
$ttlMinutes |
int|null |
No | Time-to-live in minutes (auto-expires after) |
Returns: ['email', 'domain', 'sessionToken', 'ttlMinutes', 'expiresAt']
Get Session Status
$session = $client->tempEmail->getSession(string $token);
Check if a temporary email session is still active and get session details.
Delete Temporary Email
$client->tempEmail->delete(string $token);
Permanently delete a temporary email session and all associated messages.
Temp Email Messages
Read individual messages from temporary email sessions using the session token.
Read Message
$message = $client->messages->read(string $token, int $uid);
| Parameter | Type | Required | Description |
|---|---|---|---|
$token |
string |
Yes | Session token from create() |
$uid |
int |
Yes | Message UID |
Returns: ['uid', 'from', 'subject', 'text', 'html', 'date', 'seen']
Accounts
Manage persistent email accounts on your custom domains. Full CRUD operations for email account lifecycle management.
List Accounts
$accounts = $client->accounts->list();
Returns: Array of ['email', 'domain', 'createdAt'] objects.
Create Account
$account = $client->accounts->create(string $email, string $password);
Delete Accounts
$result = $client->accounts->delete(array $emails);
Returns: ['deletedCount' => 2]
Change Password
$client->accounts->changePassword(string $email, string $newPassword);
Inbox & Messages
Read emails from persistent account inboxes. Access full message content including HTML, plain text, headers, and metadata.
List Inbox Messages
$messages = $client->inbox->list(string $email);
Returns: Array of ['uid', 'from', 'subject', 'date', 'seen'] objects.
Read Full Message
$message = $client->inbox->read(int $uid, string $email);
Returns: ['uid', 'from', 'subject', 'text', 'html', 'date', 'seen']
Verification Codes
Automatically extract OTP verification codes from emails sent by popular services. Supports regex-based code extraction for accurate results.
$code = $client->verification->getCode(string $service, string $email);
Supported services: facebook, twitter, google, icloud, instagram, tiktok, discord, linkedin
Returns: ['code', 'service', 'email', 'from', 'subject', 'date']
List Supported Services
$services = \EvilMail\Resources\Verification::supportedServices();
Random Email Generator
Generate random email accounts with auto-generated usernames and secure passwords. Ideal for bulk account creation and testing.
Preview Random Email
$preview = $client->randomEmail->preview(?int $passwordLength);
Returns: ['username', 'email', 'password', 'domain']
Batch Create Random Emails
$batch = $client->randomEmail->create(string $domain, ?int $count, ?int $passwordLength);
| Parameter | Type | Required | Description |
|---|---|---|---|
$domain |
string |
Yes | Domain for the new email accounts |
$count |
int|null |
No | Number of accounts to create |
$passwordLength |
int|null |
No | Length of generated passwords |
Returns: ['count', 'emails' => [['email', 'password', 'note?'], ...]]
Domains
List available email domains grouped by tier — free domains, premium domains, and your custom domains.
List Customer Domains
$domains = $client->domains->list();
Returns: ['free', 'premium', 'customer', 'packageType', 'authenticated']
List Public Domains
$publicDomains = $client->domains->listPublic();
Returns all publicly available domains (no authentication required).
Shortlinks
Generate short URLs for temporary email sessions, useful for sharing or bookmarking.
$link = $client->shortlink->create(string $token, string $type);
| Parameter | Type | Required | Description |
|---|---|---|---|
$token |
string |
Yes | Session token |
$type |
string |
Yes | Link type (e.g., 'session') |
Returns: ['shortUrl', 'code']
Error Handling
The SDK provides granular exception handling with typed exception classes for every error scenario:
| Exception | HTTP Status | When |
|---|---|---|
AuthenticationException |
401, 403 | Invalid or missing API key |
ValidationException |
400, 422 | Invalid request parameters |
NotFoundException |
404 | Resource not found (email, message, etc.) |
RateLimitException |
429 | Too many requests — includes retry-after |
EvilMailException |
Any other | Base exception for all API errors |
use EvilMail\Exceptions\AuthenticationException; use EvilMail\Exceptions\NotFoundException; use EvilMail\Exceptions\RateLimitException; use EvilMail\Exceptions\ValidationException; use EvilMail\Exceptions\EvilMailException; try { $code = $client->verification->getCode('google', 'user@yourdomain.com'); echo "Your code: " . $code['code']; } catch (AuthenticationException $e) { echo "Invalid API key: " . $e->getMessage(); } catch (NotFoundException $e) { echo "No verification email found yet"; } catch (RateLimitException $e) { echo "Rate limited — retry after " . $e->getRetryAfter() . " seconds"; } catch (ValidationException $e) { print_r($e->getErrors()); } catch (EvilMailException $e) { echo "API error [{$e->getStatusCode()}]: " . $e->getMessage(); }
Use Cases
- Automated Testing — Generate disposable email addresses for end-to-end test suites
- Sign-up Verification — Create temp emails and extract verification codes automatically
- Email Account Provisioning — Bulk create and manage email accounts via API
- Privacy Protection — Use anonymous email addresses to protect user identity
- Bot & Automation Workflows — Integrate email capabilities into PHP scripts and cron jobs
- SaaS Onboarding Flows — Automate email verification during user registration
- QA & Staging Environments — Isolate email testing without polluting real inboxes
Related SDKs
| Language | Package | Repository |
|---|---|---|
| Node.js | evilmail |
Evil-Mail/evilmail-node |
| PHP | evilmail/evilmail-php |
Evil-Mail/evilmail-php |
| Python | evilmail |
Evil-Mail/evilmail-python |
| Go | evilmail-go |
Evil-Mail/evilmail-go |
Links
- EvilMail Website — Temporary & custom domain email platform
- API Documentation — Full REST API reference
- Chrome Extension — Disposable temp email in your browser
- Firefox Add-on — Temp email for Firefox
- Mobile App — Privacy-first email on Android
License
This SDK is released under the MIT License.
Support
- Issues: github.com/Evil-Mail/evilmail-php/issues
- Email: support@evilmail.pro
- Website: evilmail.pro
evilmail/evilmail-php 适用场景与选型建议
evilmail/evilmail-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mail」 「email」 「sdk」 「otp」 「API-Client」 「privacy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 evilmail/evilmail-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 evilmail/evilmail-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 evilmail/evilmail-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
Mail libraries used by Zimbra Api
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.
Laravel contact us form package to send email and save to database
Laravel IMAP client
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 38
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-17