[wp-trac] [WordPress Trac] #43542: Duplicate MIME-Version header

WordPress Trac noreply at wordpress.org
Wed Apr 11 18:51:00 UTC 2018


#43542: Duplicate MIME-Version header
-------------------------------------------------+-------------------------
 Reporter:  junktrunk                            |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Mail                                 |     Version:  4.9.4
 Severity:  normal                               |  Resolution:
 Keywords:  needs-patch good-first-bug           |     Focuses:
  reporter-feedback 2nd-opinion                  |
-------------------------------------------------+-------------------------
Changes (by studyboi):

 * keywords:  needs-patch good-first-bug reporter-feedback => needs-patch
     good-first-bug reporter-feedback 2nd-opinion


Comment:

 To solve the problem of having the header be duplicated by having this
 function called twice, I added a fail-safe to prevent it.  It checks
 whether a header has been created yet before executing the code to add
 one.
 {{{
 // Set custom headers
         if ( !empty( $headers ) ) {
                 foreach ( (array) $headers as $name => $content ) {
                         // Only add custom header if not one that will be
 added automatically
                         // by wp-includes/class-phpmailer.php
                         if (('MIME-Version' !== $name) && ('X-Mailer' !==
 $name)){
                                 if (get_header($name) == ""){
                                         $phpmailer->addCustomHeader(
 sprintf( '%1$s: %2$s', $name, $content ) );
                                 }
                         }
                 }
 }}}

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


More information about the wp-trac mailing list