email-log icon indicating copy to clipboard operation
email-log copied to clipboard

Check compatibility with MailPoet3 plugin

Open sudar opened this issue 5 years ago • 5 comments

sudar avatar Jun 19 '20 03:06 sudar

No, email is not getting triggered in my local. It is also not logged in email logs. Please refer the error message under newsletter tab.

Screenshot from 2020-06-18 18-41-54

esudalaimadan avatar Jun 19 '20 06:06 esudalaimadan

They are extending PHPMailer to create their own mailer class. class WordPressMailer extends \PHPMailer {

esudalaimadan avatar Jun 22 '20 05:06 esudalaimadan

@esudalaimadan

Okay. See if they have any filter/hook that we can use to log the emails that are sent by Mail Poet.

sudar avatar Jun 22 '20 10:06 sudar

MailPoet 3 is not firing any hooks before they send emails and therefore it is not straightforward to log emails send through MailPoet.

We may have to explore this more to find out a proper way to log emails from MailPoet 3.

See #29 regarding MailPoet 2

sudar avatar Jun 30 '20 11:06 sudar

This works:

if( ! class_exists( \PHPMailer::class )) {

	class Intercept extends PHPMailer\PHPMailer\PHPMailer {
		public function send() {

			error_log( $this->Body );

			return parent::send();
		}
	}

	/**
	 * MailPoet checks has PHPMailer already been loaded. By loading it earlier, we get to specify the class.
	 *
	 * @see PHPMailerLoader::load()
	 * @see wp-content/plugins/mailpoet/lib/Mailer/WordPress/PHPMailerLoader.php
	 */

	class_alias( Intercept::class, 'PHPMailer' );
}

It should be possible to hook that to only MailPoet actions, i.e. hook early on the AJAX and Cron actions that MailPoet uses.

BrianHenryIE avatar Mar 06 '22 00:03 BrianHenryIE