Skip to content

Commit 200d9d1

Browse files
authored
Merge pull request #60 from SparkPost/issue-59
Fix ReplyTo for latest wordpress
2 parents 0bb2bb2 + 029eac8 commit 200d9d1

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

mailer.http.class.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,12 @@ protected function get_request_headers($hide_api_key = false)
255255
}
256256

257257
/**
258-
* Returns the list of Reply-To headers
258+
* Returns the list of Reply-To recipients
259+
* For WordPress version below 4.6
259260
* @return array
261+
* TODO Remove this when wordpress does not support version below 4.6
260262
*/
261-
protected function get_reply_to()
263+
protected function parse_reply_to_from_custom_header()
262264
{
263265
$replyTos = array();
264266
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()
271273
return implode(',', $replyTos);
272274
}
273275

276+
/**
277+
* Returns list of Reply-To recipients
278+
* For WordPress 4.6 and above
279+
* @return array Formatted list of reply tos
280+
*/
281+
protected function parse_reply_to()
282+
{
283+
$replyTos = array();
284+
foreach ($this->ReplyTo as $reply_to) {
285+
$name = $reply_to[1];
286+
$email = $reply_to[0];
287+
if(empty($name)) {
288+
$replyTos[] = $email;
289+
} else {
290+
$replyTos[] = sprintf('%s <%s>', $name, $email);
291+
}
292+
}
293+
294+
return implode(',', $replyTos);
295+
}
296+
297+
protected function get_reply_to()
298+
{
299+
$wp_version = get_bloginfo('version');
300+
if(version_compare($wp_version, '4.6') == -1) { // if lower than 4.6
301+
return $this->parse_reply_to_from_custom_header();
302+
} else {
303+
return $this->parse_reply_to();
304+
}
305+
}
306+
274307
protected function build_recipient($email, $name = '', $header_to = '') {
275308
$recipient = array(
276309
'address' => array(

readme.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Contributors: sparkpost, rajuru
33
Tags: sparkpost, smtp, wp_mail, mail, email
44
Requires at least: 4.0
5-
Tested up to: 4.4.2
6-
Stable tag: 2.4.0
5+
Tested up to: 4.6
6+
Stable tag: 2.4.1
77
License: GPLv2 or later
88

99
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.
4747

4848
== Changelog ==
4949

50+
= 2.4.1=
51+
- Fix Reply-To header issue with WordPress 4.6
52+
5053
= 2.4.0 =
5154
- Add supports for CC and BCC using HTTP API
5255

wordpress-sparkpost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Plugin Name: SparkPost
77
Plugin URI: http://sparkpost.com/
88
Description: Send all your email from Wordpress through SparkPost, the world's most advanced email delivery service.
9-
Version: 2.4.0
9+
Version: 2.4.1
1010
Author: SparkPost
1111
Author URI: http://sparkpost.com
1212
License: GPLv2 or later

0 commit comments

Comments
 (0)