Skip to content

Mail: subjects with a few accented characters are sent blank (lib/PHPMailer 5.1) #523

Closed

Description

@caseysoftware

Branch: dev-5.0.0 (fixed on dev-6.0.0, which uses phpmailer/phpmailer ^7.1 from Composer)

What happens
Outgoing mail whose subject (or any encoded header) is mostly ASCII but contains a few non-ASCII characters goes out with an empty value. For example, the subject Ümlaut Corp is sent as:

Subject: =?utf-8?Q??=

Strings that are mostly non-ASCII switch to Base64 (B) encoding and survive, e.g. Société Générale Équipe → =?utf-8?B?U29jacOp…?=.

Cause
lib/PHPMailer/class.phpmailer.php (5.1, 2009), EncodeQ() around line 1735, uses preg_replace() with the /e modifier, which was removed in PHP 7. The call fails with a warning and returns an empty string, so the Q-encoded word is empty.

Reproduce

$m = new w2p_Utilities_Mail();
$m->From('[email protected]'); $m->To('[email protected]');
$m->Subject('Ümlaut Corp');
echo $m->CreateHeader();   // Subject: =?utf-8?Q??=

Also logs: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead.

Impact
Every notification (tasks, events, forums, password reset…) whose project, task or company name has an accented character arrives with no subject. This hits most Latin-script languages (German, French, Spanish, etc.), where a name usually has only a few accented characters.

Fix options

  1. Back-port the dev-6.0.0 change: require phpmailer/phpmailer ^7.1 and have w2p_Utilities_Mail extend \PHPMailer\PHPMailer\PHPMailer (also closes the known CVEs in 5.1). Medium effort; test SMTP, mail(), queued mail and password resets.
  2. Minimal patch in lib: replace the /e call in EncodeQ() with preg_replace_callback(). Small effort, but it edits vendored code and leaves the other 5.1 issues.

Activity

  1. added
    dependencies
    php
    on Oct 30, 2026
  2. added a commit that references this issue on Nov 2, 2026
    5aa85b5
  3. kabeer7121 commented on Nov 3, 2026

    @kabeer7121

    If option 2 is the route, note that EncodeQ() has three /e calls, not one: lines 1727 (phrase), 1730 (comment) and 1735 (text/default). The phrase branch is the one AddrFormat() uses for display names (line 918, EncodeHeader(..., 'phrase')), so a From/To name like Zoë Müller is probably affected the same way as the subject. Patching only the default branch would leave that broken.

    A minimal replacement that keeps the same output for all three:

    $hex = function ($m) { return '=' . sprintf('%02X', ord($m[1])); };
    
    switch (strtolower($position)) {
      case 'phrase':
        $encoded = preg_replace_callback('/([^A-Za-z0-9!*+\/ -])/', $hex, $encoded);
        break;
      case 'comment':
        $encoded = preg_replace_callback('/([\(\)\"])/', $hex, $encoded);
      case 'text':
      default:
        $encoded = preg_replace_callback('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/', $hex, $encoded);
        break;
    }

    The comment case falls through into text in the original too, so I kept that. I haven't run this against the full mail flow, so it would be worth checking a name with an accent in a task notification as well as the subject.

  4. caseysoftware commented on Nov 3, 2026

    @caseysoftware
    MemberAuthor

    Thanks for the callout. This one is already resolved in 5aa85b5 and this one will be closed when dev-5.0.0 is merged into master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatibilitydependenciesphp

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions