PhoenixKit 2.17.0: Template emails no longer need a database row
PhoenixKit 2.17.0 changes how emails sent by template name find their content. A database row is no longer the only source, so Billing’s invoice and receipt emails, and any of your own, can keep working without one.
Three places to find an email’s content
PhoenixKit.Mailer.send_from_template/4 is the function a host app or a module calls to send an email by template name. Billing uses it for its invoice, receipt, credit note and payment confirmation emails. Until now it looked the name up in the email templates table alone and answered {:error, :template_not_found} when there was no row.
It now goes through the same lookup as the sign-in emails, in this order:
- an active template in the database,
- a host override file for the recipient’s language, under
priv/phoenix_kit_templates, - content the caller passes in the new
:defaultsoption.
On a site that has the template in the database, that row still wins, so nothing changes in what is sent.
New options
:defaultstakes a map of%{subject:, text:, html:}, or a function without arguments that returns one. Use the function for text built withgettext/1: it runs in the recipient’s language.:localerenders the email in a given language.:pathssets the folders searched for override files, in place of the configured ones.
Without :locale, the language comes from the recipient. A plain email address carries no preference, so such an email is rendered in the site’s content language, where the old code used English unless a locale was passed.
Usage counting on the template only happens when a database template supplied the content. The send is logged either way.
Upgrading
No migration and no configuration. Update the dependency. If your app calls send_from_template/4, add :defaults to those calls, so the emails keep a source of content if the templates table goes away. Until then, adding them changes nothing. The {:error, :template_inactive} result is gone from the documentation; it could never be returned.
Full release notes: PhoenixKit 2.17.0
2.17.0 · 6 September 2026
Changed
-
Mailer.send_from_template/4no longer depends on the email templates table. It is core’s generic host-facing send API, and it resolved names from the database alone — answering{:error, :template_not_found}when there was no row. That table is being retired, andphoenix_kit_billingreaches through this function for its invoice, receipt, credit-note and payment-confirmation emails, so dropping the table with this path untouched would have stopped those emails silently, with an error shape the caller already tolerates.It now resolves through
PhoenixKit.Email.Content, in order: an active database template, then a host override file for the recipient’s locale, then the caller’s own:defaults.Nothing changes for an install that has a row — the database layer still wins, exactly as it does for the auth emails. This ships ahead of the schema move on purpose, so no caller is ever in a window where its emails depend on a path that no longer works.
Three new options:
Option Effect :defaultscontent to fall back to — a %{subject:, text:, html:}map, or a zero-arity function returning one. Prefer the function forgettext/1content: it is evaluated inside the recipient’s locale:localerender in this locale instead of the one resolved from the recipient (a bare address carries no preference, so that falls through to the site’s content language) :pathshost override roots to search, overriding the configured ones A host or module that calls this function should add
:defaultsbefore the table is retired. Until then, adding them changes nothing. -
PhoenixKit.Email.Content.resolve/5accepts:locale, for callers whose recipient is a bare address rather than a user, and treats an explicitnil:pathsas “use the configured roots”.
Fixed
{:error, :template_inactive}is documented as no longer returned bysend_from_template/4, and never was:get_active_template_by_name/1already filters onstatus == "active", so the branch that returned it was unreachable.
PhoenixKit 2.17.0. Install or update: {:phoenix_kit, "~> 2.17"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.