| @@ -12,8 +12,18 @@ | ||
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | public function overrideEmailFunction($args) |
| 15 | 15 | { |
| 16 | + // A previous email in the same request may have registered the "blockEmailSending" and "blockEmailSendingPostSMTP" hooks below. | |
| 17 | + // We remove them systematically so each email is evaluated independently and we never missblock an email | |
| 18 | + remove_action('phpmailer_init', [$this, 'blockEmailSending']); | |
| 19 | + remove_filter('post_smtp_do_send_email', [$this, 'blockEmailSendingPostSMTP']); | |
| 20 | + | |
| 21 | + // Let integrators exclude specific emails from AcyMailing's handling | |
| 22 | + if (!apply_filters('acym_override_wp_mail', true, $args)) { | |
| 23 | + return $args; | |
| 24 | + } | |
| 25 | + | |
| 16 | 26 | if (empty($args['to'])) { |
| 17 | 27 | return $args; |
| 18 | 28 | } |
| 19 | 29 | |
| @@ -52,8 +62,9 @@ | ||
| 52 | 62 | $contentType = trim($type); |
| 53 | 63 | if (stripos($charsetContent, 'boundary=') !== false) { |
| 54 | 64 | $boundary = trim(str_replace(['BOUNDARY=', 'boundary=', '"'], '', $charsetContent)); |
| 55 | 65 | } |
| 66 | + // Avoid setting an empty $content_type. | |
| 56 | 67 | } elseif (trim($content) !== '') { |
| 57 | 68 | $contentType = trim($content); |
| 58 | 69 | } |
| 59 | 70 | } else { |
| @@ -104,9 +115,9 @@ | ||
| 104 | 115 | } |
| 105 | 116 | |
| 106 | 117 | public function blockEmailSending(&$phpmailer) |
| 107 | 118 | { |
| 108 | - $phpmailer = new FakePhpMailer(); | |
| 119 | + $phpmailer = new MailDisabler(); | |
| 109 | 120 | } |
| 110 | 121 | |
| 111 | 122 | public function blockEmailSendingPostSMTP($shouldSend) |
| 112 | 123 | { |