Make WordPress Core


Ignore:
Timestamp:
11/11/2025 02:34:32 AM (4 months ago)
Author:
westonruter
Message:

Mail: Improve multipart message handling in wp_mail().

This improves how wp_mail() handles Content-Type headers for multipart messages, preventing cases where the header could be duplicated.

Developed in https://github.com/WordPress/wordpress-develop/pull/9500

Props SirLouen, gitlost, rmccue, westi, MattyRob, bgermann, nacin, SergeyBiryukov, dd32, MikeHansenMe, Kleor, kitchin, JeffMatson, abcd95, westonruter, christinecooper, JohnVieth, dawidadach, imokweb, ayeshrajans, lakshyajeet, tusharbharti, sajjad67.
Fixes #15448.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/pluggable.php

    r61188 r61201  
    175175     *              instead of PHPMailer's default validator.
    176176     * @since 6.9.0 Added $embeds parameter.
     177     * @since 6.9.0 Improved Content-Type header handling for multipart messages.
    177178     *
    178179     * @global PHPMailer\PHPMailer\PHPMailer $phpmailer
     
    352353                                    $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) );
    353354                                    $charset  = '';
     355                                    if ( preg_match( '~^multipart/(\S+)~', $content_type, $matches ) ) {
     356                                        $content_type = 'multipart/' . strtolower( $matches[1] ) . '; boundary="' . $boundary . '"';
     357                                    }
    354358                                }
    355359
     
    547551                    }
    548552                }
    549             }
    550 
    551             if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
    552                 $phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) );
    553553            }
    554554        }
Note: See TracChangeset for help on using the changeset viewer.