SparkPost / wordpress-sparkpost

WordPress plugin to use SparkPost email
https://wordpress.org/plugins/sparkpost/
20 stars 15 forks source link

Require PHPMailer\Exception #163

Closed janneleppanen closed 3 years ago

janneleppanen commented 3 years ago

Fixes #162

SparkPost plugin includes PHPMailer but don't include PHPMailer\Exception, which causes an error when sending email.

Error happens because WordPress Core will never include PHPMailer/Exception, because SparkPost has already included PHPMailer. WordPress won't include PHPMailer/Exception, bacause of this code in wp-includes/pluggable.php:

// (Re)create it, if it's gone missing.
if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) {
    require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
    require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
    require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
    $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );

    $phpmailer::$validator = static function ( $email ) {
        return (bool) is_email( $email );
    };
}
davekiss commented 3 years ago

@bkemper can you please consider merging this?

bkemper commented 3 years ago

@janneleppanen Thank you for the contribution. @davekiss Thank you for the nudge. @JiveDig Thank you for verifying it is working correct (see https://github.com/SparkPost/wordpress-sparkpost/issues/162#issuecomment-718928088). I need to update the docs and I'll get this patch pushed ASAP.