我正在以编程方式创建一个 drupal 用户帐户,代码如下。除了遵循标准用户创建规则的 Drupal 之外,一切似乎都可以正常工作,主要是发送一封电子邮件以确认电子邮件地址。因此,用户是在 Drupal 中创建的,但确认电子邮件永远不会发送。
电子邮件在安装中工作正常。如果我使用标准注册表单,用户会按预期收到电子邮件并可以完成注册过程。
关于我需要做什么才能让 user_save 知道发送确认电子邮件的任何提示?
function _webform_submit($form, &$form_state) {
$data = $form_state['values']['submitted_tree'];
drupal_set_message('Data is: <pre>' . print_r($data, TRUE) . '</pre>');
if (array_key_exists('create_user', $data)) {
drupal_set_message('Found create_user.');
$name = $data['email'];
$account_id = db_query("SELECT uid FROM {users} WHERE name = :name", array(':name' => $name))->fetchField();
$account = new stdClass();
if ($account_id) {
//$account->uid = $account_id;
drupal_set_message("Found existing user");
}
else {
$pass = user_password();
drupal_set_message("Creating a new user: " . $name . " with pw: " . $pass );
$account->is_new = TRUE;
$account->status = TRUE;
foreach($data as $key => $value) {
//If this is an array, likely checkboxes.
if (gettype($value) == 'array') {
foreach($value as $arr_key => $arr_val) {
$edit[$arr_val]['und'][0]['value'] = '1';
}
}
else {
$edit[$key]['und'][0]['value'] = $value;
}
}
$edit['name'] = $name;
//$edit['pass'] = $pass;
$edit['mail'] = $name;
$edit['status'] = 1;
$edit['init'] = $name;
user_save($account, $edit);
}
}
}