Conversation
supportFatal error: Class ‘PHPMailer\PHPMailer\PHPMailer’ not found in …\wp-content\plugins\wp-greet\wpg-func-mail.php on line 48 Occurs on wp version 4.9.x … probably due to the use statement, which should be inside if ( (float) $wp_version >= 5.5 ) { } This topic was modified 5 years, 6 months ago by yezzz . This topic was modified 5 years, 6 months ago by yezzz . Reason: removed part of the url
Hello yezzz, thank you for this hint. Can you please give the PHP and WordPress Version you are using? It is easier to rebuild the error then. Thanks
Sure. PHP 7.2, WP 4.9.16. BTW, moving the use statement inside the condition mentioned above is also not possible (giving fatal error). I just learned that the statement cannot be used inside block scope, so it should be handled differently.
Maybe you should use wp_mail() or global $phpmailer. Check out class handling in wp_mail source
If wp_mail() or global $phpmailer requires too many changes then you can use class_alias . The following works fine for me, but you need to check for wp => 5.5 //use PHPMailer\PHPMailer\PHPMailer as PHPMailer; if ( (float) $wp_version >= 5.5 ) { if ( ! class_exists( 'PHPMailer\\PHPMailer\\PHPMailer' ) ) { require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php'; require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; } class_alias('PHPMailer\PHPMailer\PHPMailer','PHPMailer'); } else { Alternatively you could create another alias for both cases and extend that. This reply was modified 5 years, 6 months ago by yezzz .
Thanks for all your hints. I decided to separate this in two files and include accordingly. So, I can better make changes if necessary for future releases. I will publish it in a few minutes. Please test it and let me know if the problem is gone.
Will test it… in the meantime had some fun with thickbox …
Yes, v5.9 seems to work well 🙂
Hello yezzz, thank you for this hint. Can you please give the PHP and WordPress Version you are using? It is easier to rebuild the error then. Thanks
Sure. PHP 7.2, WP 4.9.16. BTW, moving the use statement inside the condition mentioned above is also not possible (giving fatal error). I just learned that the statement cannot be used inside block scope, so it should be handled differently.
Maybe you should use wp_mail() or global $phpmailer. Check out class handling in wp_mail source
If wp_mail() or global $phpmailer requires too many changes then you can use class_alias . The following works fine for me, but you need to check for wp => 5.5 //use PHPMailer\PHPMailer\PHPMailer as PHPMailer; if ( (float) $wp_version >= 5.5 ) { if ( ! class_exists( 'PHPMailer\\PHPMailer\\PHPMailer' ) ) { require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php'; require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php'; require_once ABSPATH . WPINC . '/PHPMailer/Exception.php'; } class_alias('PHPMailer\PHPMailer\PHPMailer','PHPMailer'); } else { Alternatively you could create another alias for both cases and extend that. This reply was modified 5 years, 6 months ago by yezzz .
Thanks for all your hints. I decided to separate this in two files and include accordingly. So, I can better make changes if necessary for future releases. I will publish it in a few minutes. Please test it and let me know if the problem is gone.
Will test it… in the meantime had some fun with thickbox …
Yes, v5.9 seems to work well 🙂