Home / Archive / MemberPress: Add Email Recipients to Specific Emails
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Add Email Recipients to Specific Emails

This code snippet adds additional email recipients to the MemberPress email recipient list if the email subject contains a specific text.

The code sample uses the payment of text. Thus, when the code snippet is applied, all MemberPress emails containing the payment of text in the email subject will be affected. The code snippet will add the email addresses specified in the code to the recipients list for the emails in question.

The sample code will add [email protected] and [email protected] email addresses to the recipient list.

The code snippet trigger can be modified to use a different phrase by replacing the "payment of" text with the needed phrase in small letter on this line:

if( strpos( strtolower( $subject ), 'payment of' ) !== false ) {

To change the email addresses that should be added to the email recipient list, replace [email protected] and [email protected] email addresses with the actual email addresses on these lines:

// Add email recipients
$recipients[] = '[email protected]';
$recipients[] = '[email protected]';

To add additional email addresses to the list, add more email address lines to this part of the code. For example:

// Add email recipients
$recipients[] = '[email protected]';
$recipients[] = '[email protected]';
$recipients[] = '[email protected]';

Code Preview
php
<?php
add_filter( 'mepr-wp-mail-recipients', function( $recipients, $subject, $message, $headers ) {
  // Check if the email subject contains "payment of"
  if( strpos( strtolower( $subject ), 'payment of' ) !== false ) {
    // Add email recipients
    $recipients[] = '[email protected]';
    $recipients[] = '[email protected]';
  }
  return $recipients;
}, 10, 4 );

Comments

Add a Comment