Skip to content

[6.x] Forms 2: Pass email addresses to custom mail jobs as strings - #16020

Merged
jasonvarga merged 3 commits into
forms-2from
forms-2-fix-email-strings
Nov 24, 2026
Merged

jasonvarga merged 3 commits into
forms-2from
forms-2-fix-email-strings

Conversation

@jasonvarga

@jasonvarga jasonvarga commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

After a CP save, Forms 2 stores an email connection's to, cc, bcc and reply_to as arrays, and passed them on as arrays to the send_email_job class and any Email subclass it builds. In 6.x these were always comma-separated strings, so custom jobs or mailers doing explode(',', $config['to']), string concatenation and the like would break the first time someone edited a form in the CP.

  • Storage, the CP editor, validation and the preview still use arrays. The four keys are joined with , when the job is built, in both Connectors\Email::job() and the deprecated SendEmails job. Joining loses nothing: Antlers tags are self-contained, so rendering the joined string gives the same addresses as rendering each item.
  • Statamic\Forms\Email now splits comma-separated strings before resolving field: tokens, so field:email, team@example.com resolves both. It still accepts arrays.
  • email_config in email views gets strings again, as in 6.x.
  • Converting legacy string addresses for the CP editor no longer splits on commas inside Antlers tags or quoted strings in tags. Before, {{ x ?? "a@example.com, b@example.com" }} was cut in half and failed validation on save.

field: tokens are resolved after the whole string has been through Antlers. In theory an Antlers value that renders to field:other would resolve another field of the same submission. Resolving only the tokens present before rendering would need the parser to track token positions through Antlers output. That adds complexity to close a gap that only lets a submission read its own values, so I left it out.

Upgrade note

Email recipients can now be chosen from a form field. In send_email_job classes and Email subclasses, these appear as field:handle tokens in the comma-separated to, cc, bcc and reply_to strings. If your custom code splits these addresses itself instead of passing the config to Statamic\Forms\Email, you'll need to resolve those tokens to the submitted values. (This is due to forms 2 in general - not this PR specifically)

Tests

  • Core and custom job classes receive strings (EmailConnectorTest)
  • Deprecated SendEmails passes strings and still resolves field: recipients (SendEmailsTest)
  • field: tokens inside comma strings, in either position, and missing fields (EmailTest providers, which cover to/cc/bcc/reply_to); the existing array cases still pass
  • Antlers-aware legacy split (EmailConnectorTest)

jasonvarga and others added 3 commits November 24, 2026 11:33
CP-saved connections store to/cc/bcc/reply_to as arrays, but 6.x always handed custom send_email_job classes and Email subclasses comma-separated strings. Stringify them at the job boundary (connector and deprecated SendEmails), and make Email resolve field: tokens inside comma-separated strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jasonvarga
jasonvarga merged commit 81f94c3 into forms-2 Nov 24, 2026
62 checks passed
@jasonvarga
jasonvarga deleted the forms-2-fix-email-strings branch November 24, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant