diff --git a/includes/mg-filter.php b/includes/mg-filter.php index 95e7ba4..ac9b048 100755 --- a/includes/mg-filter.php +++ b/includes/mg-filter.php @@ -93,6 +93,7 @@ function mg_detect_from_name($from_name_header = null) } $filter_from_name = null; + if ((!isset($mg_override_from) || $mg_override_from == '0') && has_filter('wp_mail_from_name')) { $filter_from_name = apply_filters( 'wp_mail_from_name', @@ -165,7 +166,7 @@ function mg_detect_from_address($from_addr_header = null): string } $filter_from_addr = null; - if (has_filter('wp_mail_from')) { + if ((!isset($mg_override_from) || $mg_override_from == '0') && has_filter('wp_mail_from')) { $filter_from_addr = apply_filters( 'wp_mail_from', $from_addr @@ -234,7 +235,7 @@ function mg_parse_headers($headers = []): array } // Explode the header - list($name, $value) = explode(':', trim($header), 2); + [$name, $value] = explode(':', trim($header), 2); // Clean up the values $name = trim($name); @@ -330,3 +331,12 @@ function mg_smtp_get_region($getRegion) return false; } } + +/** + * @return false|mixed + */ +function isReplyToOverride() +{ + $mg_opts = get_option('mailgun'); + return (bool)($mg_opts['override-from'] ?? false); +} diff --git a/includes/wp-mail-api.php b/includes/wp-mail-api.php index 7ac6298..3376963 100644 --- a/includes/wp-mail-api.php +++ b/includes/wp-mail-api.php @@ -195,7 +195,6 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) // Mainly for legacy -- process a From: header if it's there case 'from': if (strpos($content, '<') !== false) { - // So... making my life hard again? $from_name = substr($content, 0, strpos($content, '<') - 1); $from_name = str_replace('"', '', $from_name); $from_name = trim($from_name); @@ -246,12 +245,17 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) $from_name = mg_detect_from_name($from_name); $from_email = mg_detect_from_address($from_email); + $fromString = "{$from_name} <{$from_email}>"; + if (isReplyToOverride()) { + $headers['Reply-to'] = $fromString; + } - $body = array( - 'from' => "{$from_name} <{$from_email}>", + $body = [ + 'from' => $fromString, 'to' => $to, 'subject' => $subject, - ); + ]; + $rcpt_data = apply_filters('mg_mutate_to_rcpt_vars', $to); if (!is_null($rcpt_data['rcpt_vars'])) { @@ -332,8 +336,6 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) } else if ('text/html' === $content_type) { $body['html'] = $message; } else { - // Unknown Content-Type?? - error_log('[mailgun] Got unknown Content-Type: ' . $content_type); $body['text'] = $message; $body['html'] = $message; } @@ -454,7 +456,7 @@ function wp_mail($to, $subject, $message, $headers = '', $attachments = array()) } // Not sure there is any additional checking that needs to be done here, but why not? - if ($response_body->message != 'Queued. Thank you.') { + if ($response_body->message !== 'Queued. Thank you.') { mg_api_last_error($response_body->message); return false; diff --git a/mailgun.php b/mailgun.php index 30b68db..e27509c 100755 --- a/mailgun.php +++ b/mailgun.php @@ -3,7 +3,7 @@ * Plugin Name: Mailgun * Plugin URI: http://wordpress.org/extend/plugins/mailgun/ * Description: Mailgun integration for WordPress - * Version: 1.9 + * Version: 1.9.1 * Tested up to: 6.1 * Author: Mailgun * Author URI: http://www.mailgun.com/ diff --git a/readme.md b/readme.md index 53604b0..2a77f4c 100755 --- a/readme.md +++ b/readme.md @@ -5,7 +5,7 @@ Contributors: mailgun, sivel, lookahead.io, m35dev Tags: mailgun, smtp, http, api, mail, email Requires at least: 3.3 Tested up to: 6.1.1 -Stable tag: 1.9 +Stable tag: 1.9.1 Requires PHP: 5.6 License: GPLv2 or later @@ -130,7 +130,12 @@ MAILGUN_FROM_ADDRESS Type: string == Changelog == -= 1.9 (2023-01-18): = + += 1.9.1 (2023-03-26): = +- Remove not needed error logging. +- Fixed bug with Override param for Woocommerce + +- = 1.9 (2023-01-18): = - Sanitizing and escaping vars. Possible security issues = 1.8.10 (2022-12-26): = diff --git a/readme.txt b/readme.txt index 9f981d4..02599fc 100755 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Contributors: mailgun, sivel, lookahead.io, m35dev Tags: mailgun, smtp, http, api, mail, email Requires at least: 4.4 Tested up to: 6.1.1 -Stable tag: 1.9 +Stable tag: 1.9.1 Requires PHP: 5.6 License: GPLv2 or later @@ -128,6 +128,11 @@ MAILGUN_FROM_ADDRESS Type: string == Changelog == + += 1.9.1 (2023-03-26): = +- Remove not needed error logging. +- Fixed bug with Override param for Woocommerce + = 1.9 (2023-01-18): = - Sanitizing and escaping vars. Possible security issues