Skip to main content

How to create user and send mail by custom code drupal 7

$mail = 'dharmendrait08@gmail.com';
$phone = '8568077276';
$name = 'teste_user';

  //set up the user fields
  $fields = array(
    'name' => $name,
    'mail' => $mail,
    'pass' => $phone,
    'status' => 1,
    'init' => $mail,
    'roles' => array(
      DRUPAL_AUTHENTICATED_RID => 'artist',
    ),
  );

  $account = user_save('', $fields);
  $account = user_load($account->uid);
  $account->password = $fields['pass'];
  $account->field_phone['und'][0]['value'] = $phone;
  $account->field_name['und'][0]['value'] = $name;
  $account->field_user_type['und'][0]['value'] = 'Artist';
 
 
  $op = 'register_no_approval_required';
  $data = _user_mail_notify($op, $account);

Comments

  1. Another way to save user with field data:
    is_new = TRUE;
    $account->status = TRUE;
    $account->name = 'someusername';
    $account->pass = user_hash_password('somepassword');
    $account->mail = 'email@example.com';
    $account->init = 'email@example.com';
    $account->roles[5] = 'some role';
    $account->field_first_name[LANGUAGE_NONE][0]['value'] = 'some first name';
    $account->field_last_name[LANGUAGE_NONE][0]['value'] = 'some last name';
    user_save($account);

    ?>

    ReplyDelete

Post a Comment