簡體   English   中英

Codeigniter 通過電子郵件發送密碼

[英]Codeigniter send the password through email

我正在注冊,您只會在發送電子郵件進行驗證時提供您的電子郵件和姓名 我希望密碼是隨機生成的,並將通過電子郵件發送給用戶 我該怎么做

這是我的控制器:

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();


      }

我認為他的問題是密碼沒有發送給用戶

首先,您應該從數據庫中獲取密碼並通過電子郵件發送。

您在這一行“$_POST['password']”中沒有任何已發布的密碼要發送給 user 。

我不清楚你的代碼。

您的數據保存在此數組中

$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'];

因為密碼是在你的代碼中生成的,不是用戶結束的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM