# TempMail Platform - PHP Version - Project Summary

## Overview

A complete, lightweight temporary email platform built with PHP 8+, featuring a one-click web installer for easy deployment on VPS or shared hosting.

## Project Structure (26 Files)

```
temp-mail-php/
├── installer.php              # One-click web installer
├── README.md                  # Documentation
├── PROJECT_SUMMARY.md         # This file
├── nginx.conf                 # Nginx configuration
│
├── api/                       # REST API Endpoints (8 files)
│   ├── generate.php           # Generate random email
│   ├── inbox.php              # Get inbox
│   ├── read.php               # Read email
│   ├── delete.php             # Delete email
│   ├── login.php              # User login
│   ├── register.php           # User registration
│   ├── domain_add.php         # Add custom domain
│   └── domain_verify.php      # Verify domain
│
├── classes/                   # PHP Classes (4 files)
│   ├── Auth.php               # Authentication & JWT
│   ├── EmailManager.php       # Email operations
│   ├── DomainManager.php      # Domain management
│   └── MailParser.php         # Email parsing
│
├── config/                    # Configuration (2 files)
│   ├── database.php           # Database connection
│   └── config.php.example     # Config template
│
├── admin/                     # Admin Panel (5 files)
│   ├── login.php              # Admin login
│   ├── dashboard.php          # Dashboard
│   ├── domains.php            # Domain management
│   ├── emails.php             # Email monitoring
│   └── logout.php             # Logout
│
├── public/                    # Frontend (2 files)
│   ├── index.php              # Main website
│   └── .htaccess              # Apache config
│
├── cron/                      # Cron Jobs (1 file)
│   └── cleanup.php            # Cleanup expired emails
│
├── mailparser/                # Mail Parser (1 file)
│   └── parse.php              # Postfix entry point
│
└── database/                  # Database (1 file)
    └── schema.sql             # MySQL schema
```

## Features Implemented

### ✅ Core Features
- **Random Email Generation** - Create temporary emails instantly
- **Catch-all Email Receiving** - Postfix configuration for receiving all emails
- **Inbox Reading** - View emails with auto-refresh (5 seconds)
- **Email Viewing** - Read full email content (HTML & text)
- **Delete Emails** - Remove emails manually

### ✅ Domain Management
- **Custom Domains** - Users can add their own domains
- **DNS Verification** - Automatic domain ownership verification via TXT records
- **MX Record Check** - Verify email receiving capability

### ✅ API & Backend
- **REST API** - Full JSON API for all operations
- **JWT Authentication** - Secure token-based auth
- **Rate Limiting** - 100 requests/hour per IP
- **Spam Detection** - Built-in spam filtering

### ✅ Admin Panel
- **Dashboard** - Statistics and overview
- **Domain Management** - View and manage all domains
- **Email Monitoring** - View email traffic
- **User Management** - Admin login system

### ✅ Auto Installer
- **One-Click Install** - Web-based installer
- **Requirements Check** - PHP version & extensions
- **Database Setup** - Automatic table creation
- **Config Generation** - Automatic config file creation

### ✅ Security
- **Prepared Statements** - PDO with parameter binding
- **Input Validation** - All inputs sanitized
- **Password Hashing** - bcrypt with cost 12
- **CORS Protection** - Configured headers

### ✅ Maintenance
- **Auto Cleanup** - Cron job for expired emails (24h)
- **Rate Limit Cleanup** - Automatic cleanup of old rate limit data

## API Endpoints

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/api/generate.php` | GET | Generate random email |
| `/api/inbox.php` | GET | Get inbox for email |
| `/api/read.php` | GET | Read email by ID |
| `/api/delete.php` | POST | Delete email |
| `/api/login.php` | POST | User login |
| `/api/register.php` | POST | User registration |
| `/api/domain_add.php` | POST | Add custom domain |
| `/api/domain_verify.php` | POST | Verify domain |

## Database Schema

### Tables

**users**
- id, email, password, is_admin, created_at, updated_at

**system_domains**
- id, domain, active, created_at

**domains**
- id, user_id, domain, verified, verification_token, mx_record_configured, created_at

**emails**
- id, email_address, domain, from_email, from_name, subject, body, body_html, raw_email, attachments, read, spam_score, is_spam, received_at, expires_at

**rate_limits**
- id, ip_address, endpoint, requests, window_start

## Installation Methods

### Method 1: One-Click Web Installer (Recommended)
1. Upload all files to web server
2. Access `installer.php` in browser
3. Follow installation wizard

### Method 2: Manual Installation
1. Upload files
2. Create MySQL database
3. Import `database/schema.sql`
4. Copy `config/config.php.example` to `config/config.php`
5. Edit config with your settings

## Postfix Configuration

### Required Setup
1. Install Postfix: `apt-get install postfix`
2. Configure catch-all in `main.cf`
3. Add pipe to `master.cf`
4. Set up transport maps

### Example Configuration
```
# master.cf
tempmail unix - n n - - pipe
  flags=F user=www-data argv=/usr/bin/php /path/to/mailparser/parse.php

# transport
*@yourdomain.com tempmail:
```

## Cron Job Setup

```bash
# Cleanup expired emails every hour
0 * * * * /usr/bin/php /path/to/cron/cleanup.php
```

## System Requirements

- PHP 8.0+
- MySQL 5.7+ or MariaDB 10.3+
- PDO, JSON, MBString, OpenSSL extensions
- Apache or Nginx
- Postfix (for mail receiving)

## File Count: 26 Files
## Total Size: ~200KB

## Next Steps for Deployment

1. **Upload Files** - Upload to your web server
2. **Run Installer** - Access `installer.php`
3. **Configure Postfix** - Set up mail receiving
4. **Set Cron Job** - Schedule cleanup script
5. **Test** - Generate email and send test message

## Support & Documentation

- See `README.md` for detailed documentation
- Check `installer.php` for guided installation
- Review code comments for implementation details

---

**Ready to deploy!** 🚀
