我正在注册,您只需提供您的电子邮件和姓名当发送电子邮件进行验证时,我希望密码是随机生成的,并将通过电子邮件发送给用户,我该怎么做
这是我的控制器:
public function register() {
$this->form_validation->set_rules('fname', 'First Name', 'required');
$this->form_validation->set_rules('lname', 'Last Name', 'required');
$this->form_validation->set_rules('email', 'E-mail', 'required|valid_email');
if ($this->form_validation->run() == TRUE) {
$registration_data = array(
'user_firstname' => $this->input->post('fname'),
'user_lastname' => $this->input->post('lname'),
'user_email' => $this->input->post('email'),
'user_password' =>md5(rand(0, 50)),
'user_status' => '0',
'hash' => md5(rand(0, 1000))
);
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'sampleemail';
$config['smtp_pass'] = 'samplepass';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "'r'n"; //use double quotes
$this->email->initialize($config);
$address = $this->input->post('email');
$this->user_model->insert_customer($registration_data);
$this->load->library('email'); //load email library
$this->email->from('sampleemail', 'Site'); //sender's email
$subject="Welcome!"; //subject
$message= /*-----------email body starts-----------*/
'Thanks for signing up, '.$_POST['fname'].'!
Your account has been created.
Here are your login details.
-------------------------------------------------
Email : ' . $_POST['email'] . '
Password: ' . $_POST['password'] . '
-------------------------------------------------
Please click this link to activate your account:
' . base_url() . 'user/verify?' .
'email=' . $_POST['email'] . '&hash=' . 'hash';
/*-----------email body ends-----------*/
$this->email->to($address);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
}
我认为他的问题不是密码没有发送给用户
我的代码不清楚。
您的数据保存在此数组中
$registration_data = array(
'user_firstname' => $this->input->post('fname'),
'user_lastname' => $this->input->post('lname'),
'user_email' => $this->input->post('email'),
'user_password' =>md5(rand(0, 50)),
'user_status' => '0',
'hash' => md5(rand(0, 1000))
);
尝试通过此数组发送密码。例如:
$registration_data['user_password'];
因为密码已在代码中生成,并且用户未结束密码。
首先,您应该从数据库中获取密码并通过电子邮件发送。
您在此行"$_POST["密码"]"中没有任何已发布的密码发送给用户。