Question

I have a login and registration script to authenticate from android and iOS. The registration code works, I can register form app and I can see the user into the joomla db. The problem is that into the Joomla portal I use the activation mail and when I create a user from the script I receive a wrong mail. The mail have this object: COM_USERS_EMAIL_ACCOUNT_DETAILS and this text: COM_USERS_EMAIL_REGISTERED_WITH_ACTIVATION_BODY.

This is the registration script:

<?php
if( $_POST["name"] || $_POST["email"] || $_POST["username"] || $_POST["password"] ){
     define( '_JEXEC', 1 );
     define('JPATH_BASE', dirname(__FILE__) );
     define( 'DS', DIRECTORY_SEPARATOR );

     require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
     require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

     $app = JFactory::getApplication('site');
     $app->initialise();
     require_once(JPATH_BASE.DS.'components'.DS.'com_users'.DS.'models'.DS.'registration.php');

     $model = new UsersModelRegistration();
     jimport('joomla.mail.helper');
     jimport('joomla.user.helper');

     $username = $_POST['username'];
     $name = $_POST['name'];
     $email =  $_POST['email'];
     $password =  $_POST['password'];
     $block = '0';
     $sendEmail = '1';
     $activation = '';
     $data = array( 'username' => $username,
     'name' => $name,
     'email1' => $email,
     'password1' => $password, // First password field
     'password2' => $password, // Confirm password field
     'sendEmail' => $sendEmail,
     'activation' => $activation,
     'block' => 0 );
      echo $model->register($data);
}
?>

If I force the 'activation' camp Joomla overwrite with the activation code. The same with the block and sendEmail.

How can I disable the mail (only from app) or send the correct mail?

Thanks!

Was it helpful?

Solution

Since you are using the users model to save the record, it would be hard to not send the email. You would either need to write your own code to save the user or extend and override the model.

Easier way is to just make sure that the com_users language file is loaded, so those capitalized strings get replaced with the correct text, like so:

$lang = JFactory::getLanguage();
$extension = 'com_users';
$base_dir = JPATH_SITE;
$language_tag = 'en-GB';
$reload = true;
$lang->load($extension, $base_dir, $language_tag, $reload);

I'd put this after the require_once that loads the model and you should be good to go.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top