Make WordPress Core

Ticket #33972: 33972-fix-wp_mail-stale-state.patch

File 33972-fix-wp_mail-stale-state.patch, 1.3 KB (added by sachinrajcp123, 6 weeks ago)
  • src/wp-includes/pluggable.php

    diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php
    index 7b13c91..e38a5de 100644
    a b function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) { 
    390390        global $phpmailer;
    391391
    392         // (Re)create it, if it's gone missing or been destroyed
    393         if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) {
    394                 require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
    395                 require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
    396                 require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
    397 
    398                 $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
    399         }
     392        /*
     393         * Always create a new PHPMailer instance to ensure that no residual state
     394         * such as Encoding, attachments, or headers persist between wp_mail() calls.
     395         * This fixes stale configuration issues introduced by static use of $phpmailer.
     396         */
     397
     398        require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
     399        require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
     400        require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
     401
     402        $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
     403
     404        // Ensure Encoding resets to default (8bit)
     405        $phpmailer->Encoding = '8bit';
    400406