[wp-trac] [WordPress Trac] #59670: "Content-Transfer-Encoding" might break when sending multiple mails

WordPress Trac noreply at wordpress.org
Wed Oct 18 14:08:54 UTC 2023


#59670: "Content-Transfer-Encoding" might break when sending multiple mails
--------------------------+-----------------------------
 Reporter:  pluspol       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Mail          |    Version:  6.3.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When sending multiple non-multipart mails via `wp_mail` the internal
 encoding used by `PhpMailer` doesn't get resetted which may result in
 mails getting the wrong `Content-Transfer-Encoding`.

 {{{
 wp_mail('someone at somehost.tld', '8bit', '8büt'); // correctly delivered as
 8bit
 wp_mail('someone at somehost.tld', '7bit', '7bit'); // correctly delivered as
 7bit but breaks the following mails
 wp_mail('someone at somehost.tld', '8bit', '8büt'); // incorrectly delivered
 as 7bit
 }}}

 Internally PhpMailer starts with 8bit encoding in `$phpMailer->Encoding`.
 When sending a mail it might get downgraded/changed to 7bit in case the
 message doesn't contain any 8bit chars (which is the case in the first
 mail).

 However because of WP reusing the same PhpMailer instance the encoding
 doesn't get resetted to 8bit back again and therefore stays at 7bit.

 The easiest solution would be resetting the encoding manually or using an
 appropriate PhpMailer method if existing.
 Another solution would be for PhpMailer to be able to upgrade the encoding
 back to 8bit again when detecting 8bit chars.
 IMHO this depends on whether one PhpMailer instance is intended to be used
 for multiple mails or not.

 See:
 - Default encoding of PhpMailer:
 https://build.trac.wordpress.org/browser/tags/6.3.2/wp-
 includes/PHPMailer/PHPMailer.php#L92
 - Setting `Content-Transfer-Encoding` in case its not 7bit:
 https://build.trac.wordpress.org/browser/tags/6.3.2/wp-
 includes/PHPMailer/PHPMailer.php#L2744
 - Downgrading of Encoding to 7bit:
 https://build.trac.wordpress.org/browser/tags/6.3.2/wp-
 includes/PHPMailer/PHPMailer.php#L2840

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/59670>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list