diff --git a/mailer.http.class.php b/mailer.http.class.php index 896028ce..f8f5197e 100644 --- a/mailer.http.class.php +++ b/mailer.http.class.php @@ -255,10 +255,12 @@ protected function get_request_headers($hide_api_key = false) } /** - * Returns the list of Reply-To headers + * Returns the list of Reply-To recipients + * For WordPress version below 4.6 * @return array + * TODO Remove this when wordpress does not support version below 4.6 */ - protected function get_reply_to() + protected function parse_reply_to_from_custom_header() { $replyTos = array(); foreach ($this->CustomHeader as $header) { // wp_mail sets Reply-To as custom header (does not use phpmailer->addReplyTo) @@ -271,6 +273,37 @@ protected function get_reply_to() return implode(',', $replyTos); } + /** + * Returns list of Reply-To recipients + * For WordPress 4.6 and above + * @return array Formatted list of reply tos + */ + protected function parse_reply_to() + { + $replyTos = array(); + foreach ($this->ReplyTo as $reply_to) { + $name = $reply_to[1]; + $email = $reply_to[0]; + if(empty($name)) { + $replyTos[] = $email; + } else { + $replyTos[] = sprintf('%s <%s>', $name, $email); + } + } + + return implode(',', $replyTos); + } + + protected function get_reply_to() + { + $wp_version = get_bloginfo('version'); + if(version_compare($wp_version, '4.6') == -1) { // if lower than 4.6 + return $this->parse_reply_to_from_custom_header(); + } else { + return $this->parse_reply_to(); + } + } + protected function build_recipient($email, $name = '', $header_to = '') { $recipient = array( 'address' => array( diff --git a/readme.txt b/readme.txt index 880be927..f886f28f 100644 --- a/readme.txt +++ b/readme.txt @@ -2,8 +2,8 @@ Contributors: sparkpost, rajuru Tags: sparkpost, smtp, wp_mail, mail, email Requires at least: 4.0 -Tested up to: 4.4.2 -Stable tag: 2.4.0 +Tested up to: 4.6 +Stable tag: 2.4.1 License: GPLv2 or later Send all your email from WordPress through SparkPost, the most advanced email delivery service. @@ -47,6 +47,9 @@ Visit our [support site](https://support.sparkpost.com/) for help. == Changelog == += 2.4.1= +- Fix Reply-To header issue with WordPress 4.6 + = 2.4.0 = - Add supports for CC and BCC using HTTP API diff --git a/wordpress-sparkpost.php b/wordpress-sparkpost.php index f7a7eddd..99f9c170 100644 --- a/wordpress-sparkpost.php +++ b/wordpress-sparkpost.php @@ -6,7 +6,7 @@ Plugin Name: SparkPost Plugin URI: http://sparkpost.com/ Description: Send all your email from Wordpress through SparkPost, the world's most advanced email delivery service. -Version: 2.4.0 +Version: 2.4.1 Author: SparkPost Author URI: http://sparkpost.com License: GPLv2 or later