Support Forum

Help with $replyto please

RC Roy Costa
Roy Costa
Member

I’m seeking to tweak the $replyto in sp-post-support.php so that it is different than the blog site email (long story behind the “why”).  Right now, the stock code has this:

$replyto = apply_filters(‘sph_email_replyto’, ”, $newpost);

I’m not certain what this function is doing, but $replyto is of course used later in sp_send_email. However, when I test what $replyto is, it seems blank as far as I can tell (which I guess is fine as the default).  While the email is being sent “From” the blog email (which is fine), I want the reply-to to be the email of the user who posted.  So I tried this:

$replyto = $newpost[‘posteremail’];

or, I’ve tried

$replyto = ‘Reply-to: ‘ . $newpost[‘postername’] . ‘ <‘ . $newpost[‘posteremail’] . ‘>’;

Or other variations like that.  But it seems to be bombing as the emails that normally go to admins don’t work when I do that.

Please help?  Thanks!

21 Answers

New Answer

MP Mr Papa
Mr Papa
Member

its a standard wordpress filter… see more:  https://codex.wordpress.org/Plugin_API

so you would want something like:

add_filter('sph_email_replyto', 'my_reply_to', 10, 2);
function my_reply_to($reply, $newpost) {
    $reply = 'someone@site.com';
    return $reply;
}

keep in mind, the reply to is an email address… so must be valid email address…  you have text (reply-to) in there…  and to be honest, not sure if wp email supports annotated emails like that.. you might just be a plain email address…

RC Roy Costa
Roy Costa
Member

That doesn’t seem to work.  I pasted that near the top of the sp-post-support.php, and changed “someone@site.com” to be $newpost[‘posteremail’].  Am I missing something – clearly I’m not a programming pro.  Thanks.

MP Mr Papa
Mr Papa
Member

No, don’t edit our code. The purpose is filters is to allow you to interact and change our code without actually modifying it.  That way you won’t lose changes on upgrades. 

You put them code I posted in your spFunctions.php file of your simple press theme in use.  You will want to create a child theme first. We provide ready made child themes I out store to get your started (free)..

Also, check out our codex article https://simple-press.com/documentation/codex/themes/theme-basics/creating-a-child-theme/: 

RC Roy Costa
Roy Costa
Member

Okay – I placed it in our custom theme’s functions.  Still no luck.  All I did was replace ‘someone@site.com’ with $newpost[‘posteremail’].  I’m not getting a php error, but the email is not being sent out. When I remove those few lines of code however, an email does get sent out.  So just to be clear, here’s what I added to spFunctions…

add_filter(‘sph_email_replyto’, ‘my_reply_to’, 10, 2);

function my_reply_to($reply, $newpost) {
    $reply = $newpost[‘posteremail’];
    return $reply;
}

YS Yellow Swordfish
Yellow Swordfish
Member

I think the function looks fine. @mr-papa – would you agree with that? Although perhaps I would change the 10 to a higher number to make sure it gets run last.

So could it be that the email send – or perhaps receive – is baulking because the recipient and the reply to of the email are one and the same? Which, let’s be honest – doesn’t really make any logistical sense.

But then I am no real expert on the emails…

RC Roy Costa
Roy Costa
Member

I don’t think the recipient = sender.  So here’s what I think I’d like to happen…

Actual sender is the main admin email of the blog.

The poster is the person posting the forum item and I think their email = $newpost[‘posteremail’]

The recipient is the email address(es) of the forum admins, none of whom = main admin email of the blog.

The reason I do it this way is because one of the forum admins has an email address that is actually a distribution list (google groups), so that when someone posts to our church forum, everyone who is part of the group gets copied.  But when someone replies to that email, I want the reply-to to go back to the original poster, and not to the un-monitored main blog admin email.  Everything works well with the set-up, except for the reply-to part.

MP Mr Papa
Mr Papa
Member

It would be better if you posted your code and use the syntax highlighter so the code stays as code…  after pasting, select your code with mouse, then use the highlighter button on editor toolbar (looks like piece of paper and down arrow next to it)..  that way we can make sure code is valid easier…

are you running any other sp plugins?  there are others that use same filter, so like andy says, 99 would make sure its last one to run…  but that wouldnt cause email to not be sent…

so to verify what you want to do…  this email is being sent to admins of your site, letting them know there is a new post… if the admins (or your list) should reply, you want it back to the poster?  is google groups really email?  or an online bb/forum you got to read?  just trying to understand how it would work…

I assume on forum – options – email settings, you have enabled simple press email address settings (upper right)??

RC Roy Costa
Roy Costa
Member

Thank.  Here’s the code (for me to practice)…

add_filter(‘sph_email_replyto’, ‘my_reply_to’, 10, 2);

function my_reply_to($reply, $newpost) {
    $reply = $newpost[‘posteremail’];
    return $reply;
}

 

With respect to what I’m trying to do…

1) Let’s say blog general admin email address is Email_A

2) Google groups allows you to send a broadcast email to all members of a group once an email is sent to a special Google email (Email_B)

3) I created a Forum Admin account with email address = Email_B

4) When someone (with address Email_C) posts to the Forum, the “fake” account with Email_B will get an email from Email_A, since forum admins are notified automatically

5) Once Email_B receives the email from Email_A, the group gets the broadcast (Email_D, E, F, etc.)

6) So now, person Email_F gets an email through Google groups – he sees that it came from Email_A (blog email) via Email_B (google groups email).  When he clicks on REPLY, it defaults to going back to Email_A.  Instead, I would love for the reply-to to default to going back to Email_C.

7) Because of permissions issues on my host, etc., the email has to come from Email_A to Email_B.  But I think we can set the reply-to to be equal to Email_C.  At one point I had this working but have since lost the coding that did it (stupid me).

RC Roy Costa
Roy Costa
Member

Thank.  Here’s the code (for me to practice)…

add_filter(‘sph_email_replyto’, ‘my_reply_to’, 10, 2);
function my_reply_to($reply, $newpost) {
    $reply = $newpost[‘posteremail’];
    return $reply;
}

With respect to what I’m trying to do…

1) Let’s say blog general admin email address is Email_A

2) Google groups allows you to send a broadcast email to all members of a group once an email is sent to a special Google email (Email_B)

3) I created a Forum Admin account with email address = Email_B

4) When someone (with address Email_C) posts to the Forum, the “fake” account with Email_B will get an email from Email_A, since forum admins are notified automatically

5) Once Email_B receives the email from Email_A, the group gets the broadcast (Email_D, E, F, etc.)

6) So now, person Email_F gets an email through Google groups – he sees that it came from Email_A (blog email) via Email_B (google groups email).  When he clicks on REPLY, it defaults to going back to Email_A.  Instead, I would love for the reply-to to default to going back to Email_C.

7) Because of permissions issues on my host, etc., the email has to come from Email_A to Email_B.  But I think we can set the reply-to to be equal to Email_C.  At one point I had this working but have since lost the coding that did it (stupid me).

RC Roy Costa
Roy Costa
Member

And I should add – I don’t have any other functions that would conflict, as far as I know. I also tried changing the code to use my specific personal email and that didn’t work either…

add_filter('sph_email_replyto', 'my_reply_to', 99, 2);

function my_reply_to($reply, $newpost) {
    $reply = 'MY OWN EMAIL';
    return $reply;
}
MP Mr Papa
Mr Papa
Member

No, thats not how to paste code…  see image for highlighted code then hit circled button and select php or appropriate language… want this because I see illegal chars in what you posted.. but again, that would cause errors…

code.png
you did not answer my question back in #8 at bottom
MP Mr Papa
Mr Papa
Member

re filter and other plugins…  oh, okay, I thought you were using our html email plugin based on a different topic… which uses the same filter as does a couple of our other plugins…

MP Mr Papa
Mr Papa
Member

I dug into this a bit more – that is, what are wp and sp actually doing here..  and despite the name, we/they are not really updating the reply-to header for emails…  what is actually being done is updating the from email address… 

so, if code all correct, then its possible that your host is rejecting an email that is not from your server domain…

I have opened up an enhancement ticket to see if we can actually work with wp to adjust the reply-to header of emails rather than the from address…

MP Mr Papa
Mr Papa
Member

If this is indeed your problem, you might try getting around it this way:

add_filter('sph_admin_email_addresses', 'my_add_replyto_filter');
function my_add_replyto_filter($dummy) {
    add_filter('wp_mail', 'my_replyto');
    return $dummy;
}

add_filter('sph_new_post_notifications', 'my_remove_replyto_filter');
function my_remove_replyto_filter($dummy) {
    remove_filter('wp_mail', 'my_replyto');
    return $dummy;
}

function my_replyto($atts) {
    $atts['headers'] = 'email@domain.com';
    return $atts;
}

this would add a new filter to the wp mail arguments when we are getting ready to send post notifications..  this filter would modify the wp headers to add the reply-to header…  the third filter then removes the wp mail filter when we are done sneding notifications…

have to say, untested… 🙂