Skip to content

fix: give a custom To header its 3.0.0 behaviour back - #8

Merged
muhammetsafak merged 2 commits into
mainfrom
fix/restore-sendmail-to-header
Nov 25, 2026
Merged

muhammetsafak merged 2 commits into
mainfrom
fix/restore-sendmail-to-header

Conversation

@muhammetsafak

Copy link
Copy Markdown
Contributor

Summary

  • setHeader('To', ...) is no longer special-cased. On mail(), sendmail and SMTP, and in BCC batches, its output equals the 3.0.0 tag's for every spelling of the name (exact, lower, upper, mixed case, a space before or after). The previous change kept a custom To when the library wrote none, which made it a new recipient on sendmail -t.
  • Cc/Bcc keep the earlier decision: a custom one loses to the library's own header (case and spacing ignored), and is kept when the library does not write it.
  • Header names may again have spaces around them (3.0.0 accepted them); a colon, tab, inner space, control character or non-ASCII is still rejected.
  • The CR/LF/NUL, angle bracket, SMTP connection-state and MIME fixes are untouched.
  • Helpers added in this release line (EmailValidator::hasLineBreakOrNul(), hasUnsafeAddressChar(), assertSafeAddresses(), HeaderRenderer::names(), without(), isValidName(), assertSafe()) are marked @internal.
  • Tests: a 198-row matrix (To/Cc/Bcc x library writes or not x single/batch x six spellings x three transports) records the current and the 3.0.0 output; docs (Sending Mail, Encoding & Headers, Transports, API reference) and CHANGELOG.md (Unreleased) updated.

Test plan

  • vendor/bin/phpunit (611 tests)
  • vendor/bin/phpstan analyse, vendor/bin/php-cs-fixer fix --dry-run --diff, composer validate --strict, wiki-sync.sh --check docs

The previous change made setHeader('To') case-insensitive, kept it when the
library wrote no To, and so turned it into a new recipient on sendmail. To is
no longer special-cased on any transport: the library's own To line replaces a
custom header named exactly To and sits beside other spellings, as in 3.0.0,
including in BCC batches. Cc and Bcc keep losing to the library's own header.

A matrix test compares To/Cc/Bcc x six name spellings x mail()/sendmail/SMTP x
single message/BCC batches against output recorded from the 3.0.0 tag. Header
names may again have spaces around them, as in 3.0.0. The new public helpers on
EmailValidator and HeaderRenderer are marked @internal.
A display name with a CR, LF or NUL was refused although 3.0.0 wrote it safely
(an ASCII name is quoted with control characters backslash-escaped, a
non-ASCII name is Q-encoded with the line breaks removed). Address no longer
rejects the name or the raw input, only the address part; QEncoder again
encodes a NUL (=00) as 3.0.0 did. Tests pin 168 whole messages against the
3.0.0 output and check that the rendered header block gains no header from the
name.

Also: limit the "same as 3.0.0" claim for custom To to the spellings that are
accepted (spaces around the name, not tabs), test a trailing LF and tabs in
header names, document the leading space in isValidName(), and list the
behaviour changes under Changed in the changelog.
@muhammetsafak
muhammetsafak merged commit 3ba5f97 into main Nov 25, 2026
9 checks passed
@muhammetsafak
muhammetsafak deleted the fix/restore-sendmail-to-header branch November 25, 2026 16:45
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