Recently I encountered an error with one of my client’s sites’ WP Mail SMTP plugin setup. We’ve correctly set up the SMTP credentials in the plugin but the mail was never sent.
After investigating the server error logs we have found some errors pointing to “wrong instance” of PHPMailer class in one of the other plugins that came with the theme:
PHP Fatal error: Uncaught TypeError: Argument 1 passed to some_function_init() must be an instance of PHPMailer, instance of WPMailSMTP\\MailCatcherV6 given....
That function had one argument some_function_init(PHPMailer $mail)
but obviously, the type declaration of the argument was not returning an instance of PHPMailer class.
Quick research showed that since WordPress 5.5 the PHPMailer class was moved to /wp-includes/PHPMailer subdirectory. So, the PHPMailer namespace path had to be changed to that function to:
some_function_init(\PHPMailer\PHPMailer\PHPMailer $mail)
After that change, the WP Mail SMTP worked perfectly. Obviously, this is a core change that you shouldn’t normally do, but that specific situation was allowing that. What you would normally do is contact the developers of that “legacy” extension and request them to make the necessary changes and issue an update.
1 Comment