[wp-trac] [WordPress Trac] #63127: wp_mail resets custom headers when headers array is set to empty, causing loss of custom header data (e.g., boundary)

WordPress Trac noreply at wordpress.org
Wed Mar 19 14:22:47 UTC 2025


#63127: wp_mail resets custom headers when headers array is set to empty, causing
loss of custom header data (e.g., boundary)
--------------------------+-----------------------------
 Reporter:  regnalf       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Mail          |    Version:  6.7.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 In WordPress wp_mail function, when custom headers are passed as an array,
 the headers array is being reset to an empty array in line 278. This
 results in the removal of any custom headers, including important headers
 like boundary for multipart emails, which causes issues when sending
 emails with custom content types or attachments.

 Steps to Reproduce:
 1. Call wp_mail with custom headers that include a boundary in the
 Content-Type.
 2. WordPress internally resets the headers array to an empty array (line
 278).
 3. Custom headers, including the boundary, are lost in the final email
 sent by wp_mail.

 Expected Behavior:
 The custom headers passed into the wp_mail function, including boundary in
 the Content-Type, should not be reset by WordPress and should be preserved
 in the final email headers.

 Possible Fix:
 Avoid resetting the headers array to an empty array in wp_mail. Instead,
 the function should either:
 • Merge the custom headers correctly with the default ones, or
 • Handle custom headers separately to ensure they are retained.

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


More information about the wp-trac mailing list