【问题标题】:Codeigniter Sending An E-Mail Via A FunctionCodeigniter 通过函数发送电子邮件
【发布时间】:2012-03-03 04:57:21
【问题描述】:

我得到一个完整的 php 错误列表,但错误的主要原因似乎是我的 create 函数中的 line 33 调用 userRegEmail 函数 $this->_userRegEmail();

我得到的一般错误是:

Message: Missing argument 1 for Users::_userRegEmail(), called in line 33 and defined

创建函数:

public function create(){   

        //If form validation fails load previous page with errors else do the job and insert data into db

        if($this->form_validation->run('createUser') == FALSE)
        {
            $data['success'] = "";
        }else{
            $username = $this->input->post('userName');
            $password = $this->input->post('userPassword');
            $firstname = $this->input->post('userFirstName');
            $lastname = $this->input->post('userLastName');
            $email = $this->input->post('userEmail');

            $passwordHash = $this->encrypt->sha1($password); // Lets encrypt the password why sha1?  MD5 is for tossers

            $activateCode = $this->_activateCode(10);

            $this->_userRegEmail();

            // If the data is correct follow through with db insert

            if($this->users_model->createUser($username,$passwordHash,$firstname,$lastname,$email,$activateCode))
            {
                $this->session->set_flashdata('success','Thank's ' . $firstname . ' please check your email for confirmation');

                redirect('users/create' , 'refresh');

            }

        }
        $data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
        $data['pageTitle'] = "Create User";
        $this->load->view('frontend/assets/header', $data);
        $this->load->view('frontend/user_create', $data);
        $this->load->view('frontend/assets/footer');
    }

_userRegEmail() 函数:

function _userRegEmail($activateCode,$email,$firstname,$lastname){
    $data['companyName'] = $this->core_model->companyDetails()->coreCompanyName;
    $data['companyEmail'] = $this->core_model->companyDetails()->coreCompanyEmail;
    $data['companyContact'] = $this->core_model->companyDetails()->coreContactName;
    $data['firstName'] = $firstName;
    $data['lastName'] = $lastname;
    $data['email'] = $email;
    $data['activateCode'] = $activateCode;

    $this->email->from($this->core_model->companyDetails()->coreCompanyEmail, $this->core_model->companyDetails()->coreCompanyName);
    $this->email->to($email);
    $this->email->subject($this->core_model->companyDetails()->coreCompanyName, 'User Registration Confirmation');

    $messageContent= $this->load->view('email_templates/userReg','', TRUE);

    $this->email->message($messageContent);

    $this->email->send();
}

【问题讨论】:

  • _userRegEmail 需要 4 个参数...你没有给它
  • 当您在create() 中调用_userRegEmail 时,请确保您传递了函数期望的参数。看起来应该是:$this->_userRegEmail($activateCode, $email, $firstname, $lastname);

标签: php email codeigniter


【解决方案1】:

在您的 create() 函数中,将调用更改为 this

$this->_userRegEmail($activateCode, $email, $firstname, $lastname);

【讨论】:

    【解决方案2】:
    function sendemail()
    {
       $activateCode  =  $this->random_string(10);; 
       $email;        =  $this->input->post('email'); 
       $firstname     =  $this->input->post('firstname'); 
       $lastname      =  $this->input->post('lastname');
    
      $this->load->library('email');
        $this->email->from(youremailaddress@gmail.com', 'Your name');
        $this->email->to($email);
        $this->email->subject('Registration Confirmation');
        $this->email->message('Click the link below to activate your account' . anchor('http://localhost/testproject/index.php/user/confirmation_activation/' . $activation_code,'Confirmation Register'));*/
    
        $this->email->send(); 
    
       }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-22
      • 1970-01-01
      • 2012-03-22
      • 2018-03-18
      • 2013-09-06
      • 2012-12-10
      • 2016-04-16
      • 2018-10-12
      相关资源
      最近更新 更多