Tài liệu nhanh cho bộ tempmail dùng Cloudflare Email Worker + D1 + PHP proxy.
Nhận email inbound từ Cloudflare Email Routing, parse subject/body/OTP, lưu vào D1.
Lưu email_sessions và emails. Không cần server nhận request inbound từ Cloudflare.
Server gọi Worker API bằng token bí mật, frontend chỉ gọi PHP local.
Email đến @mewit.io.vn → Cloudflare Email Worker → D1 database → tempmail-api Worker → PHP proxy trên server → index.php hiển thị mail/OTP
Đặt các file trong cùng thư mục, ví dụ: /public_html/tempmail/.
| File | Mô tả |
|---|---|
config.php | Cấu hình Worker URL, token, domain. Không public nội dung token. |
create.php | Tạo/refresh session email. |
reademail.php | Đọc status/latest/otp/list mail. |
index.php | Giao diện đọc mail nhanh. |
/tempmail/create.phpfetch('/tempmail/create.php', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ username: 'testxem' })
})
Response:
{
"success": true,
"email": "testxem@mewit.io.vn",
"username": "testxem"
}
/tempmail/reademail.php?type=otp&email=testxem@mewit.io.vn{
"success": true,
"otp": "815915",
"email_id": 2,
"created_at": "2026-07-19 14:16:36"
}
/tempmail/reademail.php?type=latest&email=testxem@mewit.io.vn{
"success": true,
"email": {
"id": 2,
"from_email": "...",
"to_email": "testxem@mewit.io.vn",
"subject": "Xác minh email của bạn",
"otp": "815915",
"snippet": "Xác minh địa chỉ email...",
"body_text": "...",
"body_html": "...",
"created_at": "2026-07-19 14:16:36"
}
}
/tempmail/reademail.php?type=list&email=testxem@mewit.io.vn&limit=10/tempmail/reademail.php?type=status&email=testxem@mewit.io.vnWorker API hiện tại:
https://tempmail-api.neox97.workers.dev
PHP gọi Worker bằng header:
X-API-Token: ********
| Method | Path | Mô tả |
|---|---|---|
POST | /session/create | Tạo/refresh session |
GET | /session/status?email=... | Kiểm tra session |
GET | /latest?email=... | Lấy mail mới nhất |
GET | /otp?email=... | Lấy OTP mới nhất |
GET | /emails?email=...&limit=10 | Danh sách mail |
POST | /cleanup | Dọn session/mail cũ |
Mở:
https://api.mewit.io.vn/tempmail/
config.php, không đưa vào JavaScript frontend.body_html, nên dùng iframe sandbox.display_errors trên production PHP.DELETE FROM email_sessions
WHERE created_at < datetime('now', '-1 hour');
DELETE FROM emails
WHERE created_at < datetime('now', '-1 day');