Codeigniter通过功能发送电子邮件

时间:2012-03-03 04:57:22

标签: php email codeigniter

我得到了一个完整的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();
}

2 个答案:

答案 0 :(得分:0)

create()功能中,将呼叫更改为此

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

答案 1 :(得分:0)

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

   }