title: Codeigniter Sending An E-Mail Via A Function
body: <p>I am getting a whole list of php errors but the main cause of the errors seem to be <code>line 33</code> in my create function that is calling the <code>userRegEmail</code> function <code>$this-&gt;_userRegEmail();</code> </p>
  
  <p>The general error that I am getting is:</p>
  
  <pre><code>Message: Missing argument 1 for Users::_userRegEmail(), called in line 33 and defined
  </code></pre>
  
  <p><strong>Create Function:</strong></p>
  
  <pre><code>public function create(){   
  
          //If form validation fails load previous page with errors else do the job and insert data into db
  
          if($this-&gt;form_validation-&gt;run('createUser') == FALSE)
          {
              $data['success'] = "";
          }else{
              $username = $this-&gt;input-&gt;post('userName');
              $password = $this-&gt;input-&gt;post('userPassword');
              $firstname = $this-&gt;input-&gt;post('userFirstName');
              $lastname = $this-&gt;input-&gt;post('userLastName');
              $email = $this-&gt;input-&gt;post('userEmail');
  
              $passwordHash = $this-&gt;encrypt-&gt;sha1($password); // Lets encrypt the password why sha1?  MD5 is for tossers
  
              $activateCode = $this-&gt;_activateCode(10);
  
              $this-&gt;_userRegEmail();
  
              // If the data is correct follow through with db insert
  
              if($this-&gt;users_model-&gt;createUser($username,$passwordHash,$firstname,$lastname,$email,$activateCode))
              {
                  $this-&gt;session-&gt;set_flashdata('success','Thank&amp;#39;s ' . $firstname . ' please check your email for confirmation');
  
                  redirect('users/create' , 'refresh');
  
              }
  
          }
          $data['companyName'] = $this-&gt;core_model-&gt;companyDetails()-&gt;coreCompanyName;
          $data['pageTitle'] = "Create User";
          $this-&gt;load-&gt;view('frontend/assets/header', $data);
          $this-&gt;load-&gt;view('frontend/user_create', $data);
          $this-&gt;load-&gt;view('frontend/assets/footer');
      }
  </code></pre>
  
  <p><strong>_userRegEmail() Function:</strong></p>
  
  <pre><code>function _userRegEmail($activateCode,$email,$firstname,$lastname){
      $data['companyName'] = $this-&gt;core_model-&gt;companyDetails()-&gt;coreCompanyName;
      $data['companyEmail'] = $this-&gt;core_model-&gt;companyDetails()-&gt;coreCompanyEmail;
      $data['companyContact'] = $this-&gt;core_model-&gt;companyDetails()-&gt;coreContactName;
      $data['firstName'] = $firstName;
      $data['lastName'] = $lastname;
      $data['email'] = $email;
      $data['activateCode'] = $activateCode;
  
      $this-&gt;email-&gt;from($this-&gt;core_model-&gt;companyDetails()-&gt;coreCompanyEmail, $this-&gt;core_model-&gt;companyDetails()-&gt;coreCompanyName);
      $this-&gt;email-&gt;to($email);
      $this-&gt;email-&gt;subject($this-&gt;core_model-&gt;companyDetails()-&gt;coreCompanyName, 'User Registration Confirmation');
  
      $messageContent= $this-&gt;load-&gt;view('email_templates/userReg','', TRUE);
  
      $this-&gt;email-&gt;message($messageContent);
  
      $this-&gt;email-&gt;send();
  }
  </code></pre>