WordPress.org

Make WordPress Core

Ticket #28407: 28407.diff

File 28407.diff, 912 bytes (added by rittesh.patel, 5 years ago)

Check for whether it is associative array or sequential array for attachments

  • wp-includes/pluggable.php

     
    500500                        $phpmailer->AddCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) );
    501501        }
    502502
    503         if ( !empty( $attachments ) ) {
    504                 foreach ( $attachments as $attachment ) {
     503        if ( !empty( $attachments ) && is_array( $attachments ) ) {     
     504                // check if $attachments is associative array or not
     505                $is_assoc_array = array_keys( $attachments ) !== range( 0, count( $attachments ) - 1 );
     506                foreach ( $attachments as $name => $attachment ) {
    505507                        try {
    506                                 $phpmailer->AddAttachment($attachment);
     508                                ( $is_assoc_array ) ? $phpmailer->AddAttachment( $attachment, $name ) : $phpmailer->AddAttachment( $attachment );
    507509                        } catch ( phpmailerException $e ) {
    508510                                continue;
    509511                        }