A dynamic email service API for the eSPP project with support for multiple email providers.
| Provider Key | Description |
|---|---|
smtp |
Standard SMTP server (configured via SMTP_* env vars) |
office365 |
Office 365 SMTP (configured via OFFICE365_* env vars) |
imap |
IMAP-backed account (uses SMTP settings in IMAP_SMTP_* env vars for sending) |
pop3 |
POP3-backed account (uses SMTP settings in POP3_SMTP_* env vars for sending) |
mailtrap |
Mailtrap testing inbox (useful for staging/testing; configured via MAILTRAP_* env vars) |
/api.php
Send a JSON body (Content-Type: application/json) with the fields below. The API only accepts POST requests to /api.php.
| Parameter | Type | Required | Description |
|---|---|---|---|
to |
array | Yes | Array of recipient email addresses |
from |
string | Yes | Sender email address (displayed in recipient client). If provider policy disallows custom From, the authenticated envelope sender will be used and Reply-To will be set to this value. |
from_name |
string | No | Optional human-readable name for the sender (e.g. "Acme Inc."). When provided, it will be used with the from address as the display name. |
subject |
string | Yes | Email subject |
body |
string | Yes | HTML content of the email |
cc |
array | No | Array of CC email addresses |
bcc |
array | No | Array of BCC email addresses |
provider |
string | No | Email provider (default: value of DEFAULT_EMAIL_PROVIDER in .env). Options (keys): smtp, office365, imap, pop3, mailtrap. Provider name is case-insensitive and common variants such as office_365 are accepted. |
send_mode |
string | No |
immediate (default) sends right away inside the API request. Set to queue to enqueue the email in sys_email_queue, return a 202 response with job_id, and let the worker deliver it later.
|
Each provider can be configured to allow or disallow caller-supplied from addresses via environment flags (for example SMTP_ALLOW_CUSTOM_FROM). When a provider disallows custom From addresses, the service will:
Reply-To to the caller-specified from so replies go to the original sender.This preserves deliverability while letting callers request a custom display sender when permitted.
cURL example (replace values as needed):
curl -X POST "http://localhost:8000/api.php" \
-H "Content-Type: application/json" \
-d '{
"to": ["recipient@example.com"],
"from": "sender@example.com",
"from_name": "Acme Inc.",
"subject": "Test Email",
"body": "<h1>Hello!</h1><p>This is a test email.</p>",
"cc": ["cc@example.com"],
"provider": "smtp"
}'
Notes:
provider is omitted, the service uses the DEFAULT_EMAIL_PROVIDER from .env.from_name to control the display name shown in email clients.SMTP_ALLOW_CUSTOM_FROM) control whether arbitrary from addresses are accepted. If disallowed, the envelope sender will be the authenticated account and a Reply-To will be set so replies go to the requested from.{
"status": "success",
"code": 200,
"message": "Email sent successfully",
"effective_from": "no-reply@customdomain.com", // shown From address
"envelope_from": "espp@metadatasystem.my", // SMTP envelope sender used for delivery
"from_overridden": false // true if caller-supplied From was overridden by provider policy
}
Queued mode returns:
{
"status": "queued",
"code": 202,
"message": "Email request enqueued for processing",
"job_id": 123,
"available_at": "2025-11-22T21:24:11+08:00"
}
{
"status": "error",
"code": 400,
"message": "Missing required field: to"
}
.env.example to .env.envcomposer install to install dependencies/public/api.phpFor detailed documentation, examples, and how to add new providers, please see the README.md file.
π β Interactive API Documentation (Swagger UI)
Use tools like Postman, cURL, or the example code provided in examples.php to test the API.
Shared-hosting cron tools (such as Plesk βFetch a URLβ) can invoke the lightweight queue runner:
/queue-runner.php?token=YOUR_TOKEN&max_jobs=10
QUEUE_RUNNER_TOKEN in .env (recommended) so only authorized jobs can trigger it.max_jobs and channel query params are optional overrides; otherwise defaults come from QUEUE_RUNNER_MAX_JOBS and QUEUE_CHANNEL.bin/queue-work-once.php and returns JSON with processed_jobs for monitoring.Need a quick snapshot of whatβs stuck? Visit /queue-admin.php (HTTPS recommended) and supply ?token=YOUR_QUEUE_ADMIN_TOKEN if configured. The page shows status counts, the 50 latest jobs, and per-job logs when you enter a Job ID.
SPP Email Service API v1.0 | Built with β€οΈ for eSPP