# Premium Email Builder

The Email Builder is an optional premium module. Its PHP file is loaded only when the module is active. Its JavaScript, CSS, and WordPress media dependencies are loaded only on Email Builder administration screens.

## Storage model

Email designs are private reusable `plattio_email_tpl` posts. The sanitized design configuration is stored in `_plattio_forms_email_config`, and a design is connected to a form only when it is selected inside one of that form's notifications. Legacy designs previously stored as form child posts remain available and are detached automatically if their former parent form is deleted.

Deleting a design removes its identifier from every connected notification without deleting the notification. Duplicating a form keeps the same shared design references. Form export includes the designs referenced by that form, and import creates local copies and remaps the notification references.

## Rendering model

Notifications continue through the normal Plattio Forms and WordPress `wp_mail()` flow. When a published design is selected, the module replaces only that notification body and its content type:

- Table-based presentation markup is generated for broad email-client compatibility.
- Critical presentation rules are placed inline.
- A small responsive media query stacks columns and optionally expands selected buttons on narrow clients.
- The original recipients, subject, reply-to header, attachments, conditional logic, and global SMTP delivery remain unchanged.
- A plain-text alternative body is generated automatically and assigned to PHPMailer `AltBody`.
- When the module is inactive, unlicensed, or a selected design is unavailable, the existing plain-text notification is sent instead.

## Interactive preview

Every visible content block in the desktop and mobile preview is selectable by mouse or keyboard. Selecting a preview block switches the sidebar to Content, opens that block's settings, scrolls the settings panel to the top, and highlights the active block without changing the saved email markup. The preview remains sandboxed and does not execute scripts from custom HTML.

## Security

- All administration actions require `manage_plattio_forms`.
- AJAX save and test actions require a dedicated nonce.
- Design names and all settings are sanitized server-side.
- Custom HTML and rich-text content pass through the WordPress post HTML allowlist.
- Dynamic URLs pass through WordPress URL sanitization before they are placed in links.
- Design blocks and imported designs have hard quantity and numeric limits.
- Test messages use the same configured WordPress mailer and do not create entries.

## Available blocks

Logo, heading, rich text, image, button, divider, spacer, all form fields, one selected field, two columns, footer, and sanitized custom HTML.

Supported Smart Tags include `{notification_message}`, `{all_fields}`, `{field:field_id}`, `{form_name}`, `{form_id}`, `{entry_id}`, `{entry_date}`, `{entry_time}`, `{entry_admin_url}`, `{site_name}`, `{site_url}`, and `{email_subject}`.

## Portability

Individual and full form exports include connected email designs. Import creates new private design posts and remaps notification template identifiers. Local media attachment identifiers are intentionally removed during export and replaced with image URLs, preventing an unrelated attachment with the same numeric identifier from being selected on another website.

## Compatibility notes

Email clients differ in their HTML and CSS support. The output deliberately avoids scripts, external fonts, CSS layout systems, and WordPress administration markup. Final appearance should still be tested in the mail clients that matter to the website owner, especially Outlook desktop, Gmail, Apple Mail, and mobile clients.
