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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | smtpmailsystem-may-fail-to-send-emails-due-to-incorrect-email-extraction-from-headers-3511377-3.patch | 632 bytes | lukus |
Issue fork smtp-3511377
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:
Comments
Comment #2
lukusComment #3
lukusPatch attached.
Thanks go to @pete-b for providing solution.
Comment #5
imclean commentedThe 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