Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I send the new user activation link to my own email address instead of the user? Is there a simple function I can use to switch things out?

function bp_core_activation_signup_user_notification( $user, $user_email, $key, $meta ) {

$activate_url = bp_get_activation_page() . "?key=$key";
$activate_url = esc_url($activate_url);
$admin_email  = get_site_option( 'admin_email' );

if ( empty( $admin_email ) )
    $admin_email = 'support@' . $_SERVER['SERVER_NAME'];

// If this is an admin generated activation, add a param to email the
// user login details
$email = is_admin() ? '&e=1' : '';

$from_name       = ( '' == get_site_option( 'site_name' ) ) ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
$message         = sprintf( __( "Thanks for registering! To complete the activation of your account please click the following link:\n\n%1\$s\n\n", 'buddypress' ), $activate_url . $email );
$subject         = '[' . $from_name . '] ' . __( 'Activate Your Account', 'buddypress' );

// Send the message
$to      = apply_filters( 'bp_core_activation_signup_user_notification_to',   $user_email, $user, $user_email, $key, $meta );
$subject = apply_filters( 'bp_core_activation_signup_user_notification_subject', $subject, $user, $user_email, $key, $meta );
$message = apply_filters( 'bp_core_activation_signup_user_notification_message', $message, $user, $user_email, $key, $meta );

wp_mail( $to, $subject, $message, $message_headers );

do_action( 'bp_core_sent_user_signup_email', $admin_email, $subject, $message, $user, $user_email, $key, $meta );

// Return false to stop the original WPMU function from continuing
return false;

} if ( !is_admin() || ( is_admin() && empty( $_POST['noconfirmation'] ) ) ) add_filter( 'wpmu_signup_user_notification', 'bp_core_activation_signup_user_notification', 1, 4 );

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted
+50

Reading the code I would try something like this:

add_filter( 
    'bp_core_signup_send_validation_email_to', 
    'wpse_60858_catch_user_signup_mail' 
);

function wpse_60858_catch_user_signup_mail()
{
    // make sure to use a valid email. test it with different addresses
    return get_site_option( 'admin_email', 'fallback-address@example.com' );
}

This changes the $to part only.

share|improve this answer
    
I added this to my theme's functions and its not working :( –  Aliyah Aug 17 '12 at 1:59
    
@Aliyah Maybe you didn’t the option 'admin_email'? Try a hard coded email instead like hello@example.com. –  toscho Aug 17 '12 at 2:06
    
Heres what I have : if ( empty( $admin_email ) ) $admin_email = 'myemail@gmail.com'; –  Aliyah Aug 17 '12 at 4:00
    
Im not using wp_mail, Im using SMTP or whatever you call it. Could that be why its not working? –  Aliyah Aug 17 '12 at 4:01
    
This function uses wp_mail(). Did you change that? You shouldn’t. Install a SMTP plugin instead that hooks into wp_mail. –  toscho Aug 17 '12 at 4:14
show 4 more comments

I added a line to the code that should overwrite the user email only while performing this action. Meaning when BuddyPress sends the email of the current user to this specific notification function, it will be overwritten with the email address you add to the code. Look for the line: $user_email = 'ENTER EMAIL HERE'; towards the time and add your email. Let me know if it works.

   // Notify user of signup success.
function bp_core_activation_signup_blog_notification( $domain, $path, $title, $user, $user_email, $key, $meta ) {

// Send email with activation link.
$activate_url = bp_get_activation_page() ."?key=$key";
$activate_url = esc_url( $activate_url );
$user_email = 'ENTER EMAIL HERE';
$admin_email = get_site_option( 'admin_email' );

if ( empty( $admin_email ) )
    $admin_email = 'support@' . $_SERVER['SERVER_NAME'];

$from_name       = ( '' == get_site_option( 'site_name' ) ) ? 'WordPress' : esc_html( get_site_option( 'site_name' ) );
$message_headers = "MIME-Version: 1.0\n" . "From: \"{$from_name}\" <{$admin_email}>\n" . "Content-Type: text/plain; charset=\"" . get_option( 'blog_charset' ) . "\"\n";
$message         = sprintf( __( "Thanks for registering! To complete the activation of your account and blog, please click the following link:\n\n%1\$s\n\n\n\nAfter you activate, you can visit your blog here:\n\n%2\$s", 'buddypress' ), $activate_url, esc_url( "http://{$domain}{$path}" ) );
$subject         = '[' . $from_name . '] ' . sprintf(__( 'Activate %s', 'buddypress' ), esc_url( 'http://' . $domain . $path ) );

// Send the message
$to              = apply_filters( 'bp_core_activation_signup_blog_notification_to',   $user_email, $domain, $path, $title, $user, $user_email, $key, $meta );
$subject         = apply_filters( 'bp_core_activation_signup_blog_notification_subject', $subject, $domain, $path, $title, $user, $user_email, $key, $meta );
$message         = apply_filters( 'bp_core_activation_signup_blog_notification_message', $message, $domain, $path, $title, $user, $user_email, $key, $meta );

wp_mail( $to, $subject, $message, $message_headers );

do_action( 'bp_core_sent_blog_signup_email', $admin_email, $subject, $message, $domain, $path, $title, $user, $user_email, $key, $meta );

// Return false to stop the original WPMU function from continuing
return false;
share|improve this answer
    
Hey Brian, there are 2 wp_mail lines. I tried changing both and nothing was sent to either admin or user. Do I need to specify an admin email and replace the @support email thing? –  Aliyah Aug 16 '12 at 21:18
    
I changed my reply, it should work. The @support variable is in place in case you haven't declared an admin email in BuddyPress. –  Brian Anthony Dillingham Aug 16 '12 at 21:31
    
I added that and it is still sending an activation to the user, not me. Ps: Are you testing this yourself? –  Aliyah Aug 16 '12 at 22:38
    
any reason why you stopped using wp_mail? –  Aliyah Aug 16 '12 at 23:11
    
Im not testing it myself, I don't have buddypress installed. But mail(); is a native php function, if you are placing it correctly, both the $to and mail line replacing the wp_mail & do_action functions and its still not working, then chances are you are editing the wrong file because you just removed the two functions sending the email as far as this file is concerned. –  Brian Anthony Dillingham Aug 16 '12 at 23:37
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.