I have a script that successfully registers a user on my Joomla site via an external script.
The code is below;
<?php // database connection include('conn.php'); require_once JPATH_BASE .'/components/com_users/models/registration.php'; $model = new UsersModelRegistration(); jimport('joomla.mail.helper'); jimport('joomla.user.helper'); $language = JFactory::getLanguage(); $language->load('com_users', JPATH_SITE); // hard coded for now, in live site these will be $_POST values $username = 'adam'; $name = 'adam24'; $email = 'firstname.lastname@example.org'; $password = 'password'; $data = array( 'username' => $username, 'name' => $name, 'email1' => $email, 'password1' => $password, // First password field 'password2' => $password, // Confirm password field 'groups' =>array('10'), 'block' => 0 ); echo $model->register($data); ?>
This creates a new user, adds the to the specified group, and sends them an email.
I am using this script on a subdomain of my joomla site -
I have the registration email set to
self, so after registration the user will receive an email with a link to activate their account.
The issue is that the email body contains a link to my sub domain and not the root site. So the link is broken. The email body is as follows;
Thank you for registering at Apps Localhost. Your account is created and must be activated before you can use it. To activate the account select the following link or copy-paste it in your browser: http://apps.example.local/component/users/?task=registration.activate&token=f33c96883366318886b241d2ca93d408&Itemid=101
After activation you may login to http://apps.example.local/ using the following username and password:
Clicking this link results in a
Internal Server Error. Which is correct because that location doesn't exist on my subdomain.
I want to redirect the users to
http://apps.example.local/login and display a message like;
Your account is now active and you can login.
What do I need to change in order to get this working?
I can see the email body (
$emailBody) values are set in
components\com_users\models\registration.php (line 500).
The email body content is set in
COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY="Hello %s,\n\nThank you for registering at %s. Your account is created and must be activated before you can use it.\nTo activate the account select the following link or copy-paste it in your browser:\n%s \n\nAfter activation you may login to %s using the following username and password:\n\nUsername: %s\nPassword: %s"