[wp-trac] [WordPress Trac] #33972: static use of PHPMailer class results in stale state between calls to wp_mail()

WordPress Trac noreply at wordpress.org
Tue Aug 19 23:01:21 UTC 2025


#33972: static use of PHPMailer class results in stale state between calls to
wp_mail()
-------------------------------------------------+-------------------------
 Reporter:  codebuddy                            |       Owner:  rishabhwp
     Type:  defect (bug)                         |      Status:  assigned
 Priority:  normal                               |   Milestone:
Component:  Mail                                 |     Version:  4.3
 Severity:  critical                             |  Resolution:
 Keywords:  has-test-info good-first-bug has-    |     Focuses:
  patch changes-requested                        |
-------------------------------------------------+-------------------------
Changes (by SirLouen):

 * keywords:  has-test-info good-first-bug has-patch dev-feedback => has-
     test-info good-first-bug has-patch changes-requested


Comment:

 Hey @rishabhwp

 Thanks for the second edit, but we need some extra work.

 The first problem I clearly see is this line
 https://github.com/WordPress/wordpress-
 develop/blob/3ea6be9fa8a4973c2b01c094f062de4fd33c0aba/tests/phpunit/includes
 /mock-mailer.php#L23

 This is provoking that the test
 [https://core.trac.wordpress.org/ticket/33972#comment:6 don't match my
 manual testing]. It didn't make any sense that 8-bit was being enforced
 even when I did not add any default value to the Encoding as you did in
 `pluggable.php`. So I had to dig a little further into the tests code to
 find that line. Removing that line is necessary, as its not providing
 absolutely any value and its breaking the test.

 With this one sorted out, I believe that just by clearing up Encoding (no
 need to default to anything, like 8Bit as you did), just the same as all
 the other cleared values, will be enough to sort this problem. With this
 done the Unit Test should result in an empty value for the `Content-
 Transfer-Encoding` (like in my manual testing) as we are not explicitly
 setting up anything in particular (you can keep the message short, don't
 need to add 8 bit characters or anything like that)

 To prove that we don't really need any stunts or `8-bit` defaulting, the
 best way is to test everything directly with a clean `PHPMailer` object by
 itself to observe the default returned values.

 The first test, should obviously a very long line, to display the `quoted-
 printable` in an email

 == Example with long test:

 {{{
 <?php

 require_once 'src/PHPMailer.php';
 use PHPMailer\PHPMailer\PHPMailer;

 $mail = new PHPMailer();
 $mail->setFrom('test at test.com', 'Test');
 $mail->addAddress('test at test.com', 'Test');
 $mail->Subject = 'Test';
 $mail->Body = str_repeat('A', 1000);;
 $mail->send();

 echo 'Email sent';
 }}}

 === Result:

 {{{
 Return-Path: <test at test.com>
 Received: from sendmailpit:1025 (phpmailer_appserver_1.phpmailer_default.
 [172.23.0.8])
         by 9ac33a333c0b (Mailpit) with SMTP
         for <test at test.com>; Tue, 19 Aug 2025 22:53:10 +0000 (UTC)
 To: Test <test at test.com>
 Subject: Test
 Date: Tue, 19 Aug 2025 22:53:10 +0000
 From: Test <test at test.com>
 Message-ID:
 <mS0SO0Ld0KfwS6k63Ier90w7hZC0TzptyhgMX4vETY at phpmailer.lndo.site>
 X-Mailer: PHPMailer 6.10.0 (https://github.com/PHPMailer/PHPMailer)
 MIME-Version: 1.0
 Content-Type: text/plain; charset=iso-8859-1
 Content-Transfer-Encoding: quoted-printable

 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
 AAAAAAAAAAAAAAAAAAAAAAAAA
 }}}

 == Example with very short text:

 {{{
 <?php

 require_once 'src/PHPMailer.php';
 use PHPMailer\PHPMailer\PHPMailer;

 $mail = new PHPMailer();
 $mail->setFrom('test at test.com', 'Test');
 $mail->addAddress('test at test.com', 'Test');
 $mail->Subject = 'Test';
 $mail->Body = "Short Text";
 $mail->send();

 echo 'Email sent';
 }}}

 === Result

 {{{
 Return-Path: <test at test.com>
 Received: from sendmailpit:1025 (phpmailer_appserver_1.phpmailer_default.
 [172.23.0.8])
         by 9ac33a333c0b (Mailpit) with SMTP
         for <test at test.com>; Tue, 19 Aug 2025 22:54:40 +0000 (UTC)
 To: Test <test at test.com>
 Subject: Test
 Date: Tue, 19 Aug 2025 22:54:40 +0000
 From: Test <test at test.com>
 Message-ID:
 <oLVepBtfeRiHDrB7rIQDxIu6MmaamAcffeafldWLY at phpmailer.lndo.site>
 X-Mailer: PHPMailer 6.10.0 (https://github.com/PHPMailer/PHPMailer)
 MIME-Version: 1.0
 Content-Type: text/plain; charset=iso-8859-1

 Short Text
 }}}

 As we can see, `Content-Transfer-Encoding` by default, is not a thing, so
 with a very simple email, we should be expecting such (emptiness for
 `$mailer->Encoding`)

 I think with this you have everything to get the patch done.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/33972#comment:16>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list