mrcaspan / flarum2-email-editor
Edit the subject and wording of every email your Flarum 2.0 forum sends, and style the email layout, from the admin panel. Emails added by extensions you install later show up automatically.
Package info
github.com/MrCaspan/flarum2-email-editor
Type:flarum-extension
pkg:composer/mrcaspan/flarum2-email-editor
Requires
- flarum/core: ^2.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Change the wording of every email your forum sends, and how the emails look, from the admin panel.
It changes emails only. Nothing on the forum itself is touched, and no core or extension files are edited, so Flarum and extension updates don't undo your changes.
Features
- Every email in one list. Account activation, password reset, email change, notifications (replies, mentions, new posts, suspensions, private discussions, …) and the shared parts (greeting, sign-off, footers), grouped by extension.
- Automatically includes future extensions. The list is not hard-coded. In Flarum 2.0, core and extensions keep the words of their emails in translations named
<extension>.email.…, and Email Editor finds every one of them each time you open it. Install a new extension that sends email and its emails appear, ready to edit. - Edit the subject and body of each email, with:
- clickable placeholders (
{title},{url}, …) that insert at the cursor - the original wording shown next to your version, with a one-click "use original"
- a check that refuses text with a broken placeholder, because that would make the email fail to send
- reset per email, back to the original
- clickable placeholders (
- Layout options (optional; off by default, so emails keep Flarum's standard layout until you switch it on):
- show or hide the title, greeting ("Hey name,") and sign-off
- logo position
- colours for the page background, email background, border, text, and links and title
- extra footer text (Markdown) on every email
- Preview any email, in HTML and plain text, with sample values, including unsaved changes.
- Send test to me: emails the preview to your own address.
- Multiple languages: if you have language packs installed, pick which language's texts to edit.
- Edited texts are kept per language in your database. Texts you haven't edited keep following the original, including when an update changes it.
- Admin-only, and works with light and dark mode.
Requirements
- Flarum 2.0 or later
- PHP 8.2+ (whatever your Flarum 2.0 install needs) with the
intlextension (Flarum needs it anyway)
Installation
composer require mrcaspan/flarum2-email-editor php flarum migrate php flarum cache:clear
Then go to Admin → Extensions → Email Editor and enable it.
Updating
composer update mrcaspan/flarum2-email-editor php flarum migrate php flarum cache:clear
Uninstalling
Disable the extension, and every email goes back to its original wording and layout. To also drop its table (your edited texts), run php flarum migrate:reset --extension=mrcaspan-flarum2-email-editor. Then run composer remove mrcaspan/flarum2-email-editor.
How it works
- Wording. Edits are stored in the
email_editor_overridestable and handed to Flarum's translator as one more translation source, added after every extension's own, so they win. When you save, the extension bumps Flarum'slocale_revisionsetting (core's built-in signal for "translations stored outside the files changed"), so every server rebuilds its translation cache. - Layout. Every Flarum 2.0 email is wrapped in core's
mail::htmlandmail::plainlayouts. Email Editor registers its own versions of those two views in front of core's. While Use the custom layout is off they simply render core's original layout, so nothing changes. When it's on they render Email Editor's layout with your options. - Which texts are listed. Every translation key of the form
<namespace>.email.<…>. Keys are grouped into emails by their name (….subject,….html.body,….plain.bodyand so on).
Limits
- An extension that writes its email wording straight into its view instead of using translations can't have that wording edited. Its emails still get your layout options.
- The preview shows each email's text inside Flarum's standard notification or account email with sample values. An extension's own email view may add more (a post excerpt, say), so the real email can differ slightly.
- If an extension update adds a new placeholder to an email you've edited, your version keeps working. Click "Show original" to see what changed and add the new placeholder yourself.
API (admin only)
| Method | Endpoint | Does |
|---|---|---|
GET |
/api/email-editor?locale= |
Every email text, grouped |
POST |
/api/email-editor |
Save { locale, values: { key: text | null } } |
POST |
/api/email-editor/preview |
Render a preview |
POST |
/api/email-editor/test |
Render a preview and email it to you |
Development
The compiled JavaScript (js/dist) is committed. To change the admin page:
cd js npm install npm run build # or: npm run dev
Translations are in resources/locale/en.yml. Pull requests that add other languages are welcome.
Credits
Built by MrCaspan for PokerForum.ca.
Claude Code (Anthropic's AI coding assistant) was used to help vibe code this extension. It was tested on a real Flarum 2.0 forum. Issues and pull requests are welcome.