BuddyDev

Search

Send Welcome email to Users when they activate their account on WordPress & BuddyPress Based Social Network

Are you using BuddyPress with standard WordPress (not multisite)? In case of BuddyPress with WordPress, there is no welcome email sent to the user when they activate their account. Though, On a WordPress multisite install, the welcome email is sent on account activation.  Here is a small code snippet that will allow you to send welcome emails to the new users on normal WordPress and BuddyPress installation.

Please put the following code in your bp-custom.php


//send a welcome email when a user account is activated
add_action('bp_core_activated_user','bpdev_welcome_user_notification',10,3);
function bpdev_welcome_user_notification($user_id,$key=false,$user=false) {
	if(is_multisite())
        return ;// we don't need it for multisite
	//send the welcome mail to user
    //welcome message
	$welcome_email = __( 'Dear USER_DISPLAY_NAME,

Your new account is set up.

You can log in with the following information:
Username: USERNAME
LOGINLINK

Thanks!

--The Team @ SITE_NAME' );
    //get user details
	$user = get_userdata( $user_id );
    //get site name
    $site_name = get_bloginfo('name');
    //update the details in the welcome email
	$welcome_email = str_replace( 'USER_DISPLAY_NAME', $user->first_name, $welcome_email );
	$welcome_email = str_replace( 'SITE_NAME', $site_name, $welcome_email );
	$welcome_email = str_replace( 'USERNAME', $user->user_login, $welcome_email );
	$welcome_email = str_replace( 'LOGINLINK', wp_login_url(), $welcome_email );

    //from email
	$admin_email = get_site_option( 'admin_email' );

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

	$from_name = $site_name;//from
	$message_headers = "From: \"{$from_name}\" \n" . "Content-Type: text/plain; charset=\"" . get_option('blog_charset') . "\"\n";

    //EMAIL SUBJECT
	$subject = sprintf(__('Welcome to   %1$s '), $site_name) ;
	//SEND THE EMAIL
    wp_mail($user->user_email, $subject, $welcome_email, $message_headers);

    return true;
}

Here is a screenshot to show what it sends. You may modify the actual content if you want.

Are you going to use this code? Do you think sending a welcome email for newly registered user is a good idea? Please do share your thoughts in the comments below.

PS: This week is going to be awesome. To find out why, please do visit again :)

Get latest WordPress & BuddyPress tutorials, news and tricks in your inbox.

We send out a lovely email newsletter with the most popular stories. Be a part of it.

4 Responses to Send Welcome email to Users when they activate their account on WordPress & BuddyPress Based Social Network

  • Hey, Brajesh.
    I was wondering if it is possible to let user’s create their own page(FAN Page) like that of some big social networking website’s, is there any plugin ??
    It will engage more user’s to a particular BuddyPress Powered website’s.
    I know you can develop like that i requested :D
    Waiting for your reply Brajesh
    Thank’s .

    • I am sorry but We already have the the plugin to release this month. Hopefully, we will be able to do it next month.

      Thanks
      Brajesh

  • This worked great. Thanks!

    One thing that you might be able to help me – I use the excellent free plugin called WP Better Emails – http://wordpress.org/plugins/wp-better-emails/ and it seem that it can find all the wp_mail uses and convert them to the template however not it this case. Any idea how I can edit/change the code to make this work?

  • @Erez Weinstein, you might be doing something wrong i used same WP Better Emails and it works with this tutorial without editing any code.

    Am using a child theme.

    regards

Leave a Reply

Are you looking for support?

Please join BuddyDev Premium Club to get timely support. At the moment, We are unable to provide much support in comments. By Joining BuddyDev Premium Club, you will get guaranteed support(and we have 30 days money back guarantee too).

Your email address will not be published. All the fields marked as * are required.


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>