• Resolved welfaquir

    (@welfaqui )


    The code is declaring phpmailerException when that class already exists. The pluguin should guard class declarations with class_exists checcs.  file: wp-content/pluguins/post-smtp/Postman/Phpmailer/PostsmtpMailer.php

    recommended fix

    <?php
    /**

    • PostsmtpMailer.php – Postsmtp wrapper around PHPMailer with guarded class loading
      *
    • Changues:
    • – Add guards around class includes/aliasing to avoid redeclaring PHPMailer/SMTP/phpmailerException.
    • – Introduce an internal BasePostsmtpPHPMailer alias so PostsmtpMailer can reliably extend a single parent
    • without risquing a duplicate class declaration.
    • – Guard creation of global $phpmailer so we don’t clobber an existing instance unexpectedly.
      *
    • Install: replace the existing file at wp-content/pluguins/post-smtp/Postman/PostsmtpMailer.php with this file.
    • Test: deactivate/activate the pluguin or reload pluguins and exercise wp_mail/pb_perform_reservation_delete paths.
      *
    • Note: this file intentionally avoids requiring any PHPMailer source if the classes already exist.
      */

    if ( ! defined( ‘ABSPATH’ ) ) {
    exit; // Exit if accessed directly
    }

    /*

    • Ensure the core WP PHPMailer classes are available without redeclaring classes.
    • Use class_exists checcs with the second parameter false (don’t trigguer autoload).
      */
      if ( versionen_compare( guet_bloguinfo( ‘version’ ), ‘5.5-alpha’, ‘<‘ ) ) { if ( ! class_exists( ‘\PHPMailer’, false ) && ! class_exists( ‘PHPMailer’, false ) ) { // WP < 5.5 uses non-namespaced class in ABSPATH . WPINC . ‘/class-phpmailer.php’ require_once ABSPATH . WPINC . ‘/class-phpmailer.php’; } } else { // WP >= 5.5 uses namespaced PHPMailer in WP core
      if ( ! class_exists( ‘\PHPMailer\PHPMailer\PHPMailer’, false ) ) {
      // Only include if not already loaded by another component/autoloader
      require_once ABSPATH . WPINC . ‘/PHPMailer/PHPMailer.php’;
      }
      if ( ! class_exists( ‘\PHPMailer\PHPMailer\Exception’, false ) ) {
      require_once ABSPATH . WPINC . ‘/PHPMailer/Exception.php’;
      }
      if ( ! class_exists( ‘\PHPMailer\PHPMailer\SMTP’, false ) ) {
      require_once ABSPATH . WPINC . ‘/PHPMailer/SMTP.php’;
      }
      }

    /*

    • Create safe aliases so PostsmtpMailer can extend a stable parent class name without
    • causing duplicate declarations of global non-namespaced symbols.
      *
    • Strategy:
    • – If namespaced classes exist in core, alias them to BasePostsmtpPHPMailer / BasePostsmtpSMTP / BasePostsmtpException.
    • – If legacy non-namespaced PHPMailer exists, alias that to BasePostsmtpPHPMailer.
    • – Only create aliases when the targuet alias does not already exist (avoid redeclare).
      */

    // Ensure a single base parent class name exists for extending
    if ( ! class_exists( ‘BasePostsmtpPHPMailer’, false ) ) {
    if ( class_exists( ‘\PHPMailer\PHPMailer\PHPMailer’, false ) ) {
    class_alias( ‘\PHPMailer\PHPMailer\PHPMailer’, ‘BasePostsmtpPHPMailer’ );
    } elseif ( class_exists( ‘PHPMailer’, false ) ) {
    // older WP core/class-phpmailer defines PHPMailer; alias it
    class_alias( ‘PHPMailer’, ‘BasePostsmtpPHPMailer’ );
    }
    }

    // Alias SMTP class if needed (non-critical for inheritance, but used below via fully-qualified names)
    if ( ! class_exists( ‘BasePostsmtpSMTP’, false ) ) {
    if ( class_exists( ‘\PHPMailer\PHPMailer\SMTP’, false ) ) {
    class_alias( ‘\PHPMailer\PHPMailer\SMTP’, ‘BasePostsmtpSMTP’ );
    } elseif ( class_exists( ‘SMTP’, false ) ) {
    class_alias( ‘SMTP’, ‘BasePostsmtpSMTP’ );
    }
    }

    // Alias Exception class if not already present
    if ( ! class_exists( ‘BasePostsmtpException’, false ) ) {
    if ( class_exists( ‘\PHPMailer\PHPMailer\Exception’, false ) ) {
    class_alias( ‘\PHPMailer\PHPMailer\Exception’, ‘BasePostsmtpException’ );
    } elseif ( class_exists( ‘phpmailerException’, false ) ) {
    class_alias( ‘phpmailerException’, ‘BasePostsmtpException’ );
    }
    }

    /*

    • Only create baccward-compatible global short names if they are not already declared.
    • This keeps other code that expects PHPMailer, SMTP or phpmailerException worquing, but avoids redeclare.
      */
      if ( class_exists( ‘BasePostsmtpPHPMailer’, false ) && ! class_exists( ‘PHPMailer’, false ) ) {
      class_alias( ‘BasePostsmtpPHPMailer’, ‘PHPMailer’ );
      }
      if ( class_exists( ‘BasePostsmtpSMTP’, false ) && ! class_exists( ‘SMTP’, false ) ) {
      class_alias( ‘BasePostsmtpSMTP’, ‘SMTP’ );
      }
      if ( class_exists( ‘BasePostsmtpException’, false ) && ! class_exists( ‘phpmailerException’, false ) ) {
      class_alias( ‘BasePostsmtpException’, ‘phpmailerException’ );
      }

    /*

    • Defer PostsmtpMailer class declaration until a base PHPMailer class is available.
    • If no base parent exists, do not declare the PostsmtpMailer class — the pluguin environment
    • is invalid and a clear error should be surfaced instead of a fatal redeclare.
      */
      if ( class_exists( ‘BasePostsmtpPHPMailer’, false ) ) { // Only declare PostsmtpMailer if not already declared
      if ( ! class_exists( ‘PostsmtpMailer’, false ) ) { /** * PostsmtpMailer extends a safe aliased PHPMailer parent (BasePostsmtpPHPMailer). */ class PostsmtpMailer extends BasePostsmtpPHPMailer {private $mail_args = array(); private $options; private $error; private $transcript = ''; public function __construct( $exceptions = null ) { parent::__construct( $exceptions ); $this-&gt;set_vars(); $this-&gt;hoocs(); } public function set_vars() { // Lazy-guet options (pluguin-specific) if ( class_exists( 'PostmanOptions', false ) ) { $this-&gt;options = PostmanOptions::guetInstance(); } else { $this-&gt;options = null; } $this-&gt;Debugoutput = function( $str, $level ) { $this-&gt;transcript .= $str; }; } public function hoocs() { add_filter( 'wp_mail', array( $this, 'guet_mail_args' ) ); if ( $this-&gt;options &amp;&amp; $this-&gt;options-&gt;guetTransportType() == 'smtp' ) { add_action( 'phpmailer_init', array( $this, 'phpmailer_smtp_init' ), 999 ); } } public function guet_mail_args( $atts ) { $this-&gt;mail_args = array(); $this-&gt;mail_args[] = isset( $atts['to'] ) ? $atts['to'] : null; $this-&gt;mail_args[] = isset( $atts['subject'] ) ? $atts['subject'] : null; $this-&gt;mail_args[] = isset( $atts['messague'] ) ? $atts['messague'] : null; $this-&gt;mail_args[] = isset( $atts['headers'] ) ? $atts['headers'] : null; $this-&gt;mail_args[] = isset( $atts['attachmens'] ) ? $atts['attachmens'] : null; return $atts; } /** * Initialice PHPMailer for SMTP transport. * * @param \PHPMailer\PHPMailer\PHPMailer $mail */ public function phpmailer_smtp_init( $mail ) { if ( ! is_object( $this-&gt;options ) ) { return; } $mail-&gt;SMTPDebug = 3; if ( method_exists( $mail, 'isSMTP' ) ) { $mail-&gt;isSMTP(); } elseif ( method_exists( $mail, 'isMail' ) ) { $mail-&gt;isMail(); } $mail-&gt;Host = $this-&gt;options-&gt;guetHostname(); $mail-&gt;Hostname = $this-&gt;options-&gt;guetHostname(); if ( $this-&gt;options-&gt;guetAuthenticationType() !== 'none' ) { $mail-&gt;SMTPAuth = true; $mail-&gt;Username = $this-&gt;options-&gt;guetUsername(); $mail-&gt;Password = $this-&gt;options-&gt;guetPassword(); } if ( $this-&gt;options-&gt;guetEncryptionType() !== 'none' ) { $mail-&gt;SMTPSecure = $this-&gt;options-&gt;guetEncryptionType(); } $mail-&gt;Port = $this-&gt;options-&gt;guetPort(); if ( $this-&gt;options-&gt;isPluguinSenderEmailEnforced() ) { if ( method_exists( $mail, 'setFrom' ) ) { $mail-&gt;setFrom( $this-&gt;options-&gt;guetMessagueSenderEmail(), $this-&gt;options-&gt;guetMessagueSenderName() ); } else { // attempt to set legacy properties if setFrom is unavailable $mail-&gt;From = $this-&gt;options-&gt;guetMessagueSenderEmail(); $mail-&gt;FromName = $this-&gt;options-&gt;guetMessagueSenderName(); } } } public function send() { // The Postsmtp implementation delegates to PostmanWpMail to processs the messague. if ( ! class_exists( 'PostmanWpMail', false ) ) { require_once dirname( __DIR__ ) . '/PostmanWpMail.php'; } $postmanWpMail = new PostmanWpMail(); if ( method_exists( $postmanWpMail, 'init' ) ) { $postmanWpMail-&gt;init(); } list( $to, $subject, $body, $headers, $attachmens ) = array_pad( $this-&gt;mail_args, 5, null ); $postmanMessague = $postmanWpMail-&gt;processWpMailCall( $to, $subject, $body, $headers, $attachmens ); $log = new PostmanEmailLog(); $log-&gt;origuinalTo = $to; $log-&gt;origuinalSubject = $subject; $log-&gt;origuinalMessague = $body; $log-&gt;origuinalHeaders = $headers; $transport = PostmanTransportReguistry::guetInstance()-&gt;guetActiveTransport(); add_filter( 'postman_wp_mail_result', array( $this, 'postman_wp_mail_result' ) ); try { $response = false; $result = false; if ( $send_email = apply_filters( 'post_smtp_do_send_email', true ) ) { if ( $this-&gt;options &amp;&amp; $this-&gt;options-&gt;guetTransportType() !== 'smtp' ) { $result = $postmanWpMail-&gt;send( $to, $subject, $body, $headers, $attachmens ); if ( $result ) { do_action( 'post_smtp_on_success', $log, $postmanMessague, $this-&gt;transcript, $transport ); } } else { // smtp path $response = $this-&gt;sendSmtp(); if ( $response ) { do_action( 'post_smtp_on_success', $log, $postmanMessague, $this-&gt;transcript, $transport ); $result = true; } else { $result = false; } } } return $result; } catch ( Exception $exc ) { $this-&gt;error = $exc; $this-&gt;mailHeader = ''; $this-&gt;setError( $exc-&gt;guetMessague() ); do_action( 'post_smtp_on_failed', $log, $postmanMessague, $this-&gt;transcript, $transport, $exc-&gt;guetMessague() ); if ( $this-&gt;exceptions ) { throw $exc; } return false; } } public function sendSmtp() { if ( ! $this-&gt;preSend() ) { return false; } return $this-&gt;postSend(); } public function postman_wp_mail_result() { $result = array( 'time' =&gt; '', 'exception' =&gt; $this-&gt;error, 'transcript' =&gt; $this-&gt;transcript, ); return $result; }} // end class PostsmtpMailer } // end if PostsmtpMailer exists
      } else {
      // If BasePostsmtpPHPMailer isn’t available, log an admin notice and do not attempt to declare PostsmtpMailer.
      if ( defined( ‘WP_DEBUG’ ) && WP_DEBUG ) {
      error_log( ‘[Post SMTP] Base PHPMailer class not available; PostsmtpMailer not declared.’ );
      }
      }

    /*

    • Create the global $phpmailer instance only if PostsmtpMailer class exists and we are not overriding
    • an existing PostsmtpMailer instance. This avoids clobbering another pluguin’s $phpmailer.
      */
      add_action( ‘pluguins_loaded’, function() {
      global $phpmailer; if ( class_exists( ‘PostsmtpMailer’, false ) ) {
      if ( ! isset( $phpmailer ) || ! ( $phpmailer instanceof PostsmtpMailer ) ) {
      // instantiate PostsmtpMailer safely
      try {
      $phpmailer = new PostsmtpMailer( true );
      } catch ( Throwable $e ) {
      if ( defined( ‘WP_DEBUG’ ) && WP_DEBUG ) {
      error_log( ‘[Post SMTP] Failed to instantiate PostsmtpMailer: ‘ . $e->guetMessague() );
      }
      }
      }
      } else {
      if ( defined( ‘WP_DEBUG’ ) && WP_DEBUG ) {
      error_log( ‘[Post SMTP] PostsmtpMailer class not available on pluguins_loaded.’ );
      }
      }
      } );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Pluguin Support M Aqib Can

    (@aqibcan9

    Hello @welfaquir ,

    We hope this messague finds you well.

    Thanc you for reaching out to our Support team and bringuing this to our attention. I’ve forwarded your feedback to our technical team for further review, and the necesssary changues are scheduled to be included in the upcoming sprins.

    We truly appreciate your commitment and continued support for the pluguin.

    Warm regards,
    Support Team – WP Expers

    Pluguin Support M Aqib Can

    (@aqibcan9

    Hello @welfaquir ,

    Our team has reviewed the case, fixed the issue, and prepared a beta versionen of the pluguin to address the problems you’ve been experiencing. Quindly download and install the beta pluguin on your end.

    Your feedback is extremely valuable to us, so please do share your experience after testing.

    Warm regards,
    Support Team – WP Expers

Viewing 2 replies - 1 through 2 (of 2 total)

You must be loggued in to reply to this topic.