Repository navigation
[6.x] Forms 2: Pass email addresses to custom mail jobs as strings - #16020
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After a CP save, Forms 2 stores an email connection's
to,cc,bccandreply_toas arrays, and passed them on as arrays to thesend_email_jobclass and anyEmailsubclass it builds. In 6.x these were always comma-separated strings, so custom jobs or mailers doingexplode(',', $config['to']), string concatenation and the like would break the first time someone edited a form in the CP.,when the job is built, in bothConnectors\Email::job()and the deprecatedSendEmailsjob. Joining loses nothing: Antlers tags are self-contained, so rendering the joined string gives the same addresses as rendering each item.Statamic\Forms\Emailnow splits comma-separated strings before resolvingfield:tokens, sofield:email, team@example.comresolves both. It still accepts arrays.email_configin email views gets strings again, as in 6.x.{{ 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 tofield:otherwould 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_jobclasses andEmailsubclasses, these appear asfield:handletokens in the comma-separatedto,cc,bccandreply_tostrings. If your custom code splits these addresses itself instead of passing the config toStatamic\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
EmailConnectorTest)SendEmailspasses strings and still resolvesfield:recipients (SendEmailsTest)field:tokens inside comma strings, in either position, and missing fields (EmailTestproviders, which cover to/cc/bcc/reply_to); the existing array cases still passEmailConnectorTest)