6

When a user signs up at a Drupal site, there is a configurable message that Drupal will send the user letting them know their username and password.

I have about 1,000 users that I imported, but at the time, I didn't want to notify them - but now I do. Is there a way notify the users without reimporting them?

I looked through some of the modules I thought might contain that function, but I couldn't find it??

sepehr
  • 17,110
  • 7
  • 81
  • 119
tpow
  • 7,600
  • 11
  • 59
  • 84

1 Answers1

2

Of course there is a way: If you want to do this just one time, I recommend using a quick n' easy way... drupal_bootstrap(). In an external php file call this function to bootstrap Drupal, then load users and dispatch email messages. Here's a pseudo-code:

<?php
// ...

// Change directory to Drupal root
chdir(../../); 

// Bootstrap Drupal
require './includes/bootstrap.inc';

// You might want to pass DRUPAL_BOOTSTRAP_DATABASE instead
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$db_result = db_query('SELECT * FROM {users}');

while ($user_object = db_fetch_object($db_result)) {
    // TODO: Use drupal_mail() to send desired emails

    // User Name: $user_object->name
    // User Email: $user_object->email

    // Don't forget to pass 'em through the check_plain()
    // ...
}
// ...

Read more at Drupal API: drupal_mail() drupal_bootstrap().

sepehr
  • 17,110
  • 7
  • 81
  • 119
  • 1
    Just curious, will this allow you to email the user his/her password (as the question asked)? – Dan U. Feb 27 '10 at 10:17
  • 6
    Using this we can send users a new password, not the stored one ofcourse. Also we can make a automatic login url containing a hash, letting users to reset their passwords as drupal does by default. – sepehr Feb 27 '10 at 11:24