Make WordPress Core


Ignore:
Timestamp:
06/12/2020 03:45:30 PM (5 years ago)
Author:
desrosj
Message:

External Libraries: Upgrade PHPMailer to version 6.1.6.

Now that WordPress Core supports PHP >= 5.6, the PHPMailer library can be updated to the latest version.

The PHPMailer files now reside in a new directory, wp-includes/PHPMailer. These files are copied verbatim from the library upstream and will make updating in the future easier. For backwards compatibility, the old files will remain and trigger deprecated file warnings.

The PHPMailer class is also now under the PHPMailer\PHPMailer\PHPMailer namespace. The PHPMailer class in the global namespace has been aliased for a seamless transition.

This upgrade also clears up a handful of PHP compatibility issues detailed in #49922.

For a full list of changes, see the PHPMailer GitHub: https://github.com/PHPMailer/PHPMailer/compare/v5.2.27...v6.1.6.

Props Synchro, SergeyBiryukov, desrosj, donmhico, ayeshrajans.
Fixes #41750.

File:
1 edited

Legend:

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

    r47949 r48033  
    159159     * @since 1.2.1
    160160     *
    161      * @global PHPMailer $phpmailer
     161     * @global PHPMailer\PHPMailer\PHPMailer $phpmailer
    162162     *
    163163     * @param string|array $to          Array or comma-separated list of email addresses to send message.
     
    211211
    212212        // (Re)create it, if it's gone missing.
    213         if ( ! ( $phpmailer instanceof PHPMailer ) ) {
    214             require_once ABSPATH . WPINC . '/class-phpmailer.php';
    215             require_once ABSPATH . WPINC . '/class-smtp.php';
    216             $phpmailer = new PHPMailer( true );
     213        if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) {
     214            require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
     215            require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
     216            require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
     217            $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
    217218        }
    218219
     
    357358        try {
    358359            $phpmailer->setFrom( $from_email, $from_name, false );
    359         } catch ( phpmailerException $e ) {
     360        } catch ( PHPMailer\PHPMailer\Exception $e ) {
    360361            $mail_error_data                             = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
    361362            $mail_error_data['phpmailer_exception_code'] = $e->getCode();
     
    405406                            break;
    406407                    }
    407                 } catch ( phpmailerException $e ) {
     408                } catch ( PHPMailer\PHPMailer\Exception $e ) {
    408409                    continue;
    409410                }
     
    456457                // Only add custom headers not added automatically by PHPMailer.
    457458                if ( ! in_array( $name, array( 'MIME-Version', 'X-Mailer' ), true ) ) {
    458                     $phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
     459                    try {
     460                        $phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
     461                    } catch ( PHPMailer\PHPMailer\Exception $e ) {
     462                        continue;
     463                    }
    459464                }
    460465            }
    461466
    462467            if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
    463                 $phpmailer->addCustomHeader( sprintf( "Content-Type: %s;\n\t boundary=\"%s\"", $content_type, $boundary ) );
     468                $phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) );
    464469            }
    465470        }
     
    469474                try {
    470475                    $phpmailer->addAttachment( $attachment );
    471                 } catch ( phpmailerException $e ) {
     476                } catch ( PHPMailer\PHPMailer\Exception $e ) {
    472477                    continue;
    473478                }
     
    487492        try {
    488493            return $phpmailer->send();
    489         } catch ( phpmailerException $e ) {
     494        } catch ( PHPMailer\PHPMailer\Exception $e ) {
    490495
    491496            $mail_error_data                             = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
     
    493498
    494499            /**
    495              * Fires after a phpmailerException is caught.
     500             * Fires after a PHPMailer\PHPMailer\Exception is caught.
    496501             *
    497502             * @since 4.4.0
    498503             *
    499              * @param WP_Error $error A WP_Error object with the phpmailerException message, and an array
     504             * @param WP_Error $error A WP_Error object with the PHPMailer\PHPMailer\Exception message, and an array
    500505             *                        containing the mail recipient, subject, message, headers, and attachments.
    501506             */
Note: See TracChangeset for help on using the changeset viewer.