Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
Help with $replyto please
Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
Mar 5, 2016 - 8:31 pm

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!

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Mar 5, 2016 - 8:46 pm

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

Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
Mar 5, 2016 - 9:08 pm

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.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Mar 5, 2016 - 10:16 pm

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/docum.....-theme/: 

Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
Mar 6, 2016 - 2:53 pm

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;
}

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Mar 6, 2016 - 3:44 pm

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

andy-signature.png
YELLOW
SWORDFISH
Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
Mar 6, 2016 - 3:57 pm

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.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Mar 6, 2016 - 5:58 pm

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)??

Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
Mar 6, 2016 - 8:01 pm

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).

Avatar
Roy Costa
Member
sp_UserOfflineSmall Offline
Mar 6, 2016 - 8:02 pm

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).

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 649
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 616
Members: 17348
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10118
Posts: 79603