Problem/Motivation

The SMTPMailSystem plugin incorrectly extracts email addresses from the "From" and "Return-Path" headers when they are formatted as <email@example.com> (without a display name). The preg_match() regex requires a mandatory space before the email, which leads to extraction failures.

Steps to reproduce

- Configure SMTPMailSystem to send an email where the From address is in the format <email@example.com> (without a display name).
- Attempt to send an email.
- Observe that PHPMailer may fail to process the email, or it may be rejected by some mail servers.

Proposed resolution

- Modify the regex in SMTPMailSystem.php to correctly extract the email address when there is no display name.
- Ensure that the Return-Path header also correctly extracts just the email.
- Apply trim() to prevent issues with leading/trailing spaces.

Issue fork smtp-3511377

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

  • 3511377-smtpmailsystem-may-fail Comparecompare
  • 1 hidden branch
  • 8.x-1.x Comparecompare

Comments

lukus created an issue. See original summary.

lukus’s picture

Issue summary: View changes
lukus’s picture

Patch attached.

Thanks go to @pete-b for providing solution.

bluegeek9 made their first commit to this issue’s fork.

imclean’s picture

The Return-Path header shouldn't be set by Drupal, it's added by the receiving mail server based on the SMTP command MAIL FROM:. But that discussion has been had many times without much progress.

As for parsing address strings, why not use PHPMailer's built-in parseAddresses() function rather than managing a separate preg_match()?

https://github.com/PHPMailer/PHPMailer/blob/v6.12.0/src/PHPMailer.php#L1246

bluegeek9 changed the visibility of the branch 8.x-1.x to hidden.