Skip to:
Content
Pages
Categories
Search
Top
Bottom

Adding a filter to define headers for email notifications

  • I would love to get some feedback on this, before submitting a ticket to Trac:

    On a BP site I am managing, I am facing the issue of users responding to private messages by email, which results in their responses being sent to the site admin instead of the expected recipient.

    It’s a classic problem:

    See https://buddypress.org/support/topic/private-message-sent-to-admin-e-mail/

    …and https://buddypress.org/support/topic/why-is-site-admin-getting-users-private-messages/

    I was hoping to find a filter, that would allow me to set the Reply-To address to the address of the sender, not the site admin.

    I looked into this function, which is sending the messages: function messages_notification_new_message(...)

    Unfortunately, it uses wp_mail in this way:

    wp_mail( $email_to, $email_subject, $email_content );

    This doesn’t allow us to change the headers (such as: From, Reply to…).

    It looks a bit like an oversight, since there are filters in place for all the other pieces: for $email_to, $email_subject, $email_content.

    So my proposal for BuddyPress Core would be: add a new filter for email headers:

    $email_headers = apply_filters( 'messages_notification_new_message_headers', $headers, $sender_name, $sender_id, $ud );

    and change the wp_mail function accordingly:

    wp_mail( $email_to, $email_subject, $email_content, $email_headers );

    This would allow me to define the Reply-To header, by using a filter such as this:

    add_filter( 'messages_notification_new_message_headers', 'kino_set_notification_headers', 10, 4 );
    
    function kino_set_notification_headers( $headers, $sender_name, $sender_id, $ud ){
      
      $sender_data = get_userdata($sender_id);
      
      $headers = 'Reply-To: '.$sender_name.' <'.$sender_data->user_email.'>' . "\r\n";
      
      return $headers;
    }

    What do you think? Shall I propose this change on Trac?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Adding a filter to define headers for email notifications’ is closed to new replies.
Skip to toolbar