Joomla 1.7 - admin email notification after user registration
There are 3 user activation options in Joomla 1.6 and 1.7 (they can be found in Users > User Manager > Options > New User Account Activation):
- None - no activation required. After registration account is activated automatically and user can login. Notification email is sent to the registered user
- Self - user receives an email with a link to activate his account. Once activated, user can login.
- Admin - user receives an email with a link to verify his account. Once verified, administrators (users with "Receive System Email" option enabled) receives and email with a link to activate user's account. Once activated registered user receives a notification that his account has been activated by administrator. User can now login.
As you can see administrator is only notified about new user registration only if New User Account Activation is set to Admin. If it's set to None or Self no notification email is sent to the admin account. This behaviour is different from Joomla 1.5 where administrator was always notified.
I couldn't find a suitable extension to enable administrator notifications with none activation option so had to resort to a small hack on core Joomla files. Be aware that any change to the core files may be overwritten by a Joomla update. Always document changes you make to the core files so you can quickly re-do them if required. Also make backups of all files you modify.
Step 1
Open file:
components/com_users/models/registration.php
Scroll down to the very bottom of the code
if ($useractivation == 1)
return "useractivate";
else if ($useractivation == 2)
return "adminactivate";
else
return $user->id;
}
}
Delete line
return $user->id;
and paste following code instead:
{
// ===================================================================
// My Custom Edit. Send Notify Email to Admins start
// ===================================================================
// Compile the notification mail values.
$data = $user->getProperties();
$data['fromname'] = $config->get('fromname');
$data['mailfrom'] = $config->get('mailfrom');
$data['sitename'] = $config->get('sitename');
$data['siteurl'] = JUri::base();
$db = $this->getDbo();
$emailSubject = JText::sprintf(
'COM_USERS_EMAIL_REGISTRATION_NOTIFY_SUBJECT',
$data['name']
);
$emailBody = JText::sprintf(
'COM_USERS_EMAIL_REGISTRATION_NOTIFY_BODY',
$data['name'],
$data['email'],
$data['username']
);
// get all admin users
$query = 'SELECT name, email, sendEmail' .
' FROM #__users' .
' WHERE sendEmail=1';
$db->setQuery( $query );
$rows = $db->loadObjectList();
// Send mail to all superadministrators id
foreach( $rows as $row )
{
$return = JUtility::sendMail($data['mailfrom'], $data['fromname'], $row->email, $emailSubject, $emailBody);
// Check for an error.
if ($return !== true) {
$this->setError(JText::_('COM_USERS_REGISTRATION_ACTIVATION_NOTIFY_SEND_MAIL_FAILED'));
return false;
}
}
// ===================================================================
// My Custom Edit End
// ===================================================================
return $user->id;
}
Note: We deleted line: return $user->id; and added it back at the end only because the whole code after else now has to be in between curly brackets { and }
Step 2
Now open file language/en-GB/en-GB.com_users.ini
Note: en-GB refers to a Joomla Language. If you use different language this may be different for you
At the end of the file add following lines:
COM_USERS_EMAIL_REGISTRATION_NOTIFY_SUBJECT="New user registration details (%s)"
COM_USERS_EMAIL_REGISTRATION_NOTIFY_BODY="Hello administrator,\n\nA new user has registered.\nThis email contains their details:\n\n Name : %s \n email: %s \n Username: %s "
Obviously you can edit the text so it works best for you.
Now, after user registration (if New User Account Activation option is set to none) all admins with Receive System emails set to Yes will receive email notifications.
This was tested on Joomla 1.7, but should also work on Joomla 1.6.
Update: January 2012 - Joomla 2.5 released
Good news! Joomla 2.5 now got this functionality built in, so there is no need or any core hacks or third party add-ons. Simply go to User Manager > Options and set Notification Mail to Administrators to Yes
Joomla - Redirection after user registration
In Joomla, after successful registration, users by default are redirected to a login page (if account doesn't need to be activated). From there (after logging in) users are redirected to a user profile page. This happens even if you have Login Redirection set to something else in Login Form Module.
To change this behaviour you can redirect users after registration to any other page on your website.
To do this you need to edit a core Joomla file. Be aware that your changes may be overwritten by a Joomla update. Always document changes you make to core Joomla files so you can quickly re-do them if required.
Open file:
components/com_users/controllers/registration.php
Scroll down to the very bottom. Starting line 162 or so you will have flowing code:
// Redirect to the profile screen.
if ($return === 'adminactivate'){
$this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
}else if ($return === 'useractivate') {
$this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
} else {
$this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
}
In this section you have 3 links starting index.php?
- First one (index.php?option=com_users&view=registration&layout=complete) is executed after user registration if account has to be activated by an administrator
- Second (index.php?option=com_users&view=registration&layout=complete), if account has to be activated by user
- Third (index.php?option=com_users&view=login), if account activation is not required.
Replace links depending on type of registration you use with FULL URL of your redirection page and you are done.
For example, if user activation on my website is not required and I want to redirect users after registration to http://www.mywebsite.com/welcome-reg the updated code will be:
// Redirect to the profile screen.
if ($return === 'adminactivate'){
$this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_VERIFY'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
} else if ($return === 'useractivate') {
$this->setMessage(JText::_('COM_USERS_REGISTRATION_COMPLETE_ACTIVATE'));
$this->setRedirect(JRoute::_('index.php?option=com_users&view=registration&layout=complete', false));
} else {
$this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
$this->setRedirect(JRoute::_('http://www.mywebsite.com/welcome-reg', false));
}
Regardless to which page on your website you redirect, system message "Thank you for registering..." will be still displayed. If you don't want this message, remove full line above your redirection URL. e.g. $this->setMessage(JText::_('COM_USERS_REGISTRATION_SAVE_SUCCESS'));
If you don't require account activation (New User Account Activation set to None) this is all you need to avoid User Profile page. However, if user has to activate account via email (Account Activation set to Self) this may not be enough. Immediately after registration user will be redirected to a web page you provided in the code as expected. However, when user clicks on a link in the activation email, they will be taken to the previously mentioned login form and if they use it to login, they will get to the User Profile page. To prevent this you can disable User Profile page completely and instead redirect users to any page you like. Read this article to find out how.
Joomla 1.6
Joomla 1.7
Joomla 2.5
Joomla 1.7 language override (User-Profile Plugin)
This article explains how to change text in User - Profile plugin fields. You can use the same instructions to override pretty much any text filed in Joomla.
Let's say we want to change Address 1: to Your Address:
First off all find the original text you want to change in Joomla language file.
Language files are located in two places:
Frontend: /language
Backend:/administrator/language
In our case for the backend we open file /administrator/language/en-GB/en-GB.plg_user_profile.ini and copy following lines:
PLG_USER_PROFILE_FIELD_ADDRESS1_DESC="Choose an option for the field Address1"
PLG_USER_PROFILE_FIELD_ADDRESS1_LABEL="Address 1:"
In theory you could simply edit text in here and it would work just fine. Problem with this approach is that any Joomla update may overwrite this file with original values. This is why we should use language override files which are normally not touched by the updates.
Open backed language override file:
/administrator/language/overrides/en-GB.override.ini
paste the copied lines and change text between quotes as required:
PLG_USER_PROFILE_FIELD_ADDRESS1_DESC="Choose an option for the field Your Address"
PLG_USER_PROFILE_FIELD_ADDRESS1_LABEL="Your Address:"
This will take care of what you see in the backend.
To change text in the frontend open frontend language override file:
language/overrides/en-GB.override.ini
paste the same text and edit as required:
PLG_USER_PROFILE_FIELD_ADDRESS1_DESC="Please Enter Your Address"
PLG_USER_PROFILE_FIELD_ADDRESS1_LABEL="Your Address:"
Joomla 1.6
Joomla 1.7
Add additional fields to a Joomla 1.7 registration form
Joomla 1.6 / 1.7 has a great new feature which allows to expand registration form without any third party plugins or core hacks such as this.
Go to Extensions > Plug-in manager and enable User - Profile plugin
Open the plugin, expand Basic Options, disable not required fields and set required fields to either Optional or Required.
Enabled fields will appear at the bottom of your registration form in User Profile section.
There are 12 commonly used fields available. Unfortunately there is still no easy way to add additional fields (it is possible, just not very straight forward). However you can rename exiting fields to suit your needs. This is done via language override. Read this article to find out how.
Joomla 1.6
Joomla 1.7