INSIDE THE ENGINE

A complete engine
for PHP email.

The full feature list:
composition, recipients, personalization, delivery, security, and sent-mail storage.

PHPMailEngine brings the details of email into one consistent interface. Explore the tools for building MIME messages, managing addresses, rendering individual emails, and sending through SMTP or a local mail transfer agent.

01 / MESSAGE COMPOSITION

Compose complete MIME messages.

Message content, headers, encoding, and attachments come together inside the engine.

HTML and plain text

  • HTML message bodies with UTF-8 content.
  • Explicit plain-text content alongside the HTML message.
  • Automatic plain-text fallback generated from HTML when text is not supplied.
  • Multipart messages combining text, HTML, inline resources, and downloadable attachments.

Headers and encoding

  • Sender and subject configuration.
  • UTF-8 subject and recipient display-name encoding.
  • Automatically generated Date and Message-ID headers.
  • Automatic MIME boundaries and CRLF line handling.
  • Configurable 8bit, Base64, and quoted-printable encoding for text, HTML, inline resources, and attachments.
02 / RECIPIENT MANAGEMENT

Manage addresses as part of the message.

Independent recipient collections handle addressing, validation, and individual delivery.

Address parsing and validation

  • Separate To, Cc, and Bcc collections with multiple recipients.
  • Accept bare email addresses, Name <email> format, and comma-separated name/address pairs.
  • Trim and normalize email addresses for consistent lookup.
  • Validate addresses and retain invalid input with its reason.
  • Track invalid recipients and optionally write an invalid-address log.

List controls and recipient privacy

  • Add, remove, move, clear, count, and look up recipients.
  • Handle duplicate addresses in normalized recipient collections.
  • Retrieve recipients as arrays or formatted address lists.
  • Generate delivery envelope recipients independently of visible headers.
  • Include Bcc in delivery while excluding it from visible message headers.
  • Single-To mode sends a separate message to each To recipient; configured Cc and Bcc accompany each message.
03 / TOKENIZER AND PERSONALIZATION

Render a message for each recipient.

Reusable templates combine shared data with recipient-specific values before message processing.

Variables and template data

  • Shared template data and individual data supplied with each To recipient.
  • Recipient data overrides shared values for that recipient’s message.
  • Escaped variables for ordinary text and raw variables for trusted HTML.
  • Missing variable values fall back to an empty string.
  • Configurable variable and statement delimiters.
  • Render a template directly or use it for individualized sending.

Conditional content and repeated sections

  • Variable assignment with set statements.
  • Conditional content with if, elseif, else, and endif.
  • Repeated sections using foreach, for, and while loops.
  • Loop control with break and continue.
  • Template comments removed during rendering.
  • PHP-expression-based evaluation for developer-controlled templates.

Individual message jobs

  • Render final HTML separately for each To recipient before resource embedding and MIME generation.
  • Keep distinct template jobs for the same address when different recipient data is supplied.
  • Count individualized template jobs independently of normalized address lists.
  • Process personalized images and resources for each rendered message.
  • Configured Cc and Bcc recipients receive a copy of each personalized message.
04 / ATTACHMENTS AND INLINE RESOURCES

Bring files and images into the email.

The engine processes local resources and packages them with the message.

File and memory attachments

  • Multiple downloadable file attachments.
  • Attach in-memory strings or binary data with a filename and MIME type.
  • Automatic MIME type detection for file attachments.
  • Attachment filenames and MIME Content-Disposition handling.
  • Binary-safe attachment processing and configurable transfer encoding.
  • Validate file existence and readability before attaching.

Automatic inline embedding

  • Discover local images referenced by HTML img elements.
  • Resolve relative image paths against a supplied base path, including parent-directory paths.
  • Embed supported data URI resources.
  • Process CSS url() references in inline styles and style blocks.
  • Generate Content-ID values and rewrite local references to cid: URLs.
  • Reuse embedded resources when the same image appears more than once.
  • Preserve existing cid: references and leave remote image URLs as external references.

Resource size controls

  • Configurable maximum size for a single attachment or inline resource.
  • Configurable combined size limit for attachments and inline resources.
  • Default limits of 20 MiB per resource and 25 MiB combined, before transfer encoding.
  • Check file size before reading an attachment into memory.
  • External HTML resources are not automatically downloaded during processing.
05 / SMTP AND LOCAL DELIVERY

Choose and configure the delivery path.

Send the completed MIME message through SMTP or a Sendmail-compatible local mail transfer agent.

SMTP transport

  • Direct SMTP delivery with configurable host, port, and client HELO identity.
  • EHLO negotiation and server capability detection.
  • SMTP envelope and MAIL FROM, RCPT TO, and DATA handling.
  • SMTP dot-stuffing and message line normalization.
  • Configurable connection and transport timeouts.
  • SMTPUTF8 option with server capability checks.
  • Client-configured message size limits and checks against the server’s advertised SIZE limit.

Endpoint failover and retries

  • Configure multiple SMTP endpoints in an ordered list.
  • Set host, port, security, and credentials for individual endpoints.
  • Configure retry attempts and the delay between attempts.
  • Move to the next configured endpoint when attempts fail before message submission.
  • Automatic endpoint options for common STARTTLS and implicit TLS ports.
  • Avoid automatic retry after message submission or acceptance to reduce duplicate-delivery risk.

Sendmail-compatible local transport

  • Deliver through a local Sendmail-compatible executable.
  • Discover the executable and options from PHP’s sendmail_path setting.
  • Configure the executable path and command-line options explicitly.
  • Chunked message writing and process timeout handling.
  • Detect broken pipes, process failures, and nonzero exit codes.
  • Optional verbose diagnostics and configurable end-of-message dot handling.
06 / TRANSPORT SECURITY AND AUTHENTICATION

Authenticate and protect the connection.

Configure encrypted transports and select an authentication mechanism supported by your SMTP server.

TLS connections

  • STARTTLS and implicit TLS/SSL connection modes.
  • Automatic SMTP port and security selection.
  • TLS certificate and peer-name verification enabled by default.
  • Configurable TLS verification and crypto-method settings.
  • Explicit unencrypted mode for environments that require it.

SMTP authentication

  • LOGIN, PLAIN, and CRAM-MD5 authentication.
  • OAuth 2.0 access-token authentication through XOAUTH2 and OAUTHBEARER.
  • Automatic selection from the server’s advertised authentication mechanisms.
  • Explicit authentication-method selection or no-auth mode.
  • Accept an application-supplied OAuth access token; token acquisition and refresh remain with the application.
  • Support long XOAUTH2 responses through the SMTP continuation exchange.
07 / S/MIME MESSAGE SIGNING

Sign the completed message.

Optional detached signing uses your certificate and private key through OpenSSL.

Certificates and keys

  • Detached S/MIME signing with OpenSSL PKCS#7 support.
  • X.509 certificate and private key supplied as file paths or PEM strings.
  • Optional passphrase for protected private keys.
  • Sign the completed MIME content before transport delivery.
  • Enable or disable S/MIME signing through the public interface.
  • Clean up temporary certificate, key, and message material after signing.
08 / SENT-MAIL STORAGE AND EXPORT

Keep a copy after successful delivery.

Optional IMAP storage and EML export make the sent MIME message available beyond the transport.

IMAP Sent copies

  • Append a copy of a successfully sent message to an IMAP mailbox.
  • Configure IMAP host, port, credentials, security, and timeout.
  • Implicit TLS and IMAP STARTTLS with certificate and peer-name verification controls.
  • Set a Sent mailbox explicitly or discover it automatically where supported.
  • List server mailboxes and inspect IMAP capabilities.
  • Configure message flags and support LITERAL+ when advertised.
  • Track Sent-copy failures separately from primary email delivery.

Message inspection and EML export

  • Retrieve generated MIME headers and body for inspection.
  • Access the MIME message from the last successful send.
  • Save that sent message as an EML file.
  • Inspect the last SMTP response code and IMAP response.
  • Retrieve a separate error when IMAP Sent-copy storage fails.
09 / INTEGRATION AND DIAGNOSTICS

A simple public interface with explicit controls.

Configure the engine through a fluent API or configuration arrays.

Integration

  • Single-file, single-class implementation.
  • No Composer requirement and no external runtime packages.
  • PHP 8.2 and later; required PHP extensions depend on the features used.
  • Fluent methods for composition, recipients, authentication, and transport settings.
  • Configuration arrays for MIME, SMTP, Sendmail, and IMAP options.
  • Message construction kept separate from transport delivery.

Validation and diagnostics

  • Explicit errors for invalid configuration, unavailable resources, and transport failures.
  • CR/LF checks on SMTP address inputs and command sanitization.
  • Authentication credentials masked in ordinary SMTP diagnostics.
  • Controlled diagnostic output and process error reporting.
  • Configurable resource limits, message-size limits, and transport timeouts.
  • Invalid-recipient tracking without losing the rest of the recipient list.
WHAT’S NEXT

Preparing for release.

PHPMailEngine is in final testing ahead of its planned SourceForge release. Read the project’s story or return to the Home page for the introduction.