Skip to content

Fix duplicate Reply-To header in registration & check-in emails#16

Open
ish-sookun wants to merge 1 commit into
mainfrom
f-reply-to-duplicate-fix
Open

Fix duplicate Reply-To header in registration & check-in emails#16
ish-sookun wants to merge 1 commit into
mainfrom
f-reply-to-duplicate-fix

Conversation

@ish-sookun

Copy link
Copy Markdown
Contributor

What was wrong

After PR #13 shipped, the registration confirmation email arrived with two identical Reply-To entries (MSCC Developers Conference 2026, MSCC Developers Conference 2026).

Root cause: Envelope::replyTo is reapplied to the Mailable's $replyTo array every time Laravel hydrates the envelope. Mailable::replyTo() appends (it doesn't replace), so any re-hydration across the dispatch → queue → send lifecycle doubles the entry.

What changes

Set the configured address once, in the Mailable's constructor — serialized with the queued job, applied exactly once at render time — and drop replyTo: from the Envelope so nothing else can push a second entry.

File Change
app/Mail/Concerns/UsesConfiguredReplyTo.php Trait method renamed from configuredReplyTo() (returned an Address array) to applyConfiguredReplyTo() (calls $this->replyTo() once, void)
app/Mail/RegistrationConfirmationMail.php + app/Mail/CheckedInMail.php Constructor body calls $this->applyConfiguredReplyTo(); replyTo: removed from Envelope
tests/Feature/MailReplyToTest.php Asserts $mail->replyTo count = 1 when configured, 0 when unset; regression-guards envelope()->replyTo === [] so a future PR can't reintroduce the bug

All 44 tests pass.

Production deploy

  1. Merge & deploy as normal
  2. Restart the queue worker (or wait for the next cron tick if you set that up) so jobs queued from the new code path are used
  3. Drain any in-flight jobs that were queued under the old code (they'll still produce duplicate Reply-To). Quickest is php artisan queue:flush if there's nothing else queued — otherwise wait for them to process
  4. Trigger a test registration; the email should now have exactly one Reply-To

Test plan

  • Fresh registration on prod arrives with one Reply-To, not two
  • Reply-To still shows the configured MAIL_REPLY_TO_NAME <MAIL_REPLY_TO_ADDRESS>
  • Unset MAIL_REPLY_TO_ADDRESS → email has no Reply-To header at all (old behaviour preserved)

Reply-To was being added twice on the rendered message — once via
Envelope::replyTo and again when Laravel rehydrated the envelope at
some point in the dispatch -> queue -> send lifecycle (Mailable's
$replyTo array is appended to, not replaced).

Sets the address once in the Mailable's constructor (serialized with
the queued job, applied exactly once at render time) and removes
replyTo from the Envelope so nothing else can push a second entry.

- app/Mail/Concerns/UsesConfiguredReplyTo: trait method
  applyConfiguredReplyTo() that calls $this->replyTo() once
- RegistrationConfirmationMail + CheckedInMail: constructor calls
  applyConfiguredReplyTo(); replyTo dropped from Envelope
- tests/Feature/MailReplyToTest: assertions on $this->replyTo count
  plus a regression guard that Envelope::replyTo stays empty
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