fclose($fd); // Parse recipient (To: field) preg_match('/^To: .*<(.+?)>/m', $rawEmail, $toMatches); $toEmail = $toMatches[1] ?? ''; if (!$toEmail) exit;
$stmt = $pdo->prepare("INSERT INTO temp_mailboxes (email, token, created_at, expires_at) VALUES (?, ?, NOW(), ?)"); $stmt->execute([$email, $token, $expires]); temp mail script
// Fetch emails $stmt = $pdo->prepare("SELECT * FROM temp_emails WHERE mailbox_id = ? ORDER BY received_at DESC"); $stmt->execute([$mailbox['id']]); $emails = $stmt->fetchAll(); ?> <!DOCTYPE html> <html> <head> <title>Temp Mail Inbox</title> <meta http-equiv="refresh" content="10"> <style> body font-family: Arial; .email border-bottom:1px solid #ccc; padding:8px; </style> </head> <body> <h2>Your temporary email:</h2> <input type="text" value="<?= htmlspecialchars($mailbox['email']) ?>" id="email" readonly size="40"> <button onclick="copyToClipboard()">Copy</button> <p>Expires: <?= $mailbox['expires_at'] ?></p> 'unknown'; preg_match('/^Subject: (
// Parse subject & sender preg_match('/^From: .*<(.+?)>/m', $rawEmail, $fromMatches); $sender = $fromMatches[1] ?? 'unknown'; preg_match('/^Subject: (.+?)$/m', $rawEmail, $subjectMatches); $subject = $subjectMatches[1] ?? '(no subject)'; A typical temp mail system has five core
| Script | Language | Features | |--------|----------|----------| | (GitHub) | PHP | Simple, AJAX, Bootstrap UI | | mailcow-dockerized | Python/Go | Full mail stack with temp mail plugin | | Firemail | Node.js + MongoDB | Fast API, modern UI | | Disposemail | Go | Lightweight, single binary |
By building your own script, you , choose the retention policy , and avoid spam traps set by large providers. Part 3: How a Temp Mail Script Works (Under the Hood) Let’s dissect the architecture. A typical temp mail system has five core components:
// Simple body extraction (for plain text) $body = trim(substr($rawEmail, strpos($rawEmail, "\n\n") ?? 0));