Welcome Guest, Not a member yet? Register   Sign In
Why does sending account activation email from Codeigniter 3 fail?

I am working on a Register and Login application with CodeIgniter 3.1.4 and Twitter Bootstrap.

When a user registers, an email should be send to the address he/she provided, with an account confirmation link. The problem is that the confirmation email does not send.

In the Usermodel I have:

public function activationEmail($first_name='', $last_name='', $email='', $verification_key='') {
   $config = array(
       'useragent' => 'CodeIgniter',
       'protocol' => 'mail',
       'mailpath' => '/usr/sbin/sendmail',
       'smtp_host' => 'localhost',
       'smtp_user' => '[email protected]',
       'smtp_pass' => '******',
       'smtp_port' => 465,
       'smtp_timeout' => 55,
       'wordwrap' => TRUE,
       'wrapchars' => 76,
       'mailtype' => 'html',
       'charset' => 'utf-8',
       'validate' => FALSE,
       'priority' => 3,
       'crlf' => "\r\n",
       'newline' => "\r\n",
       'bcc_batch_mode' => FALSE,
       'bcc_batch_size' => 200,
   $messg = 'Wellcome, '. $first_name . ' ' . $last_name . '! Click the <strong><a href="'.site_url('/signin/signin'. $verification_key).'">confirmation link</a></strong> to confirm your account.';

   $this->load->library('email', $config);
   $this->email->from('[email protected]','Razvan');
   $this->email->subject('Account activation');
   return $this->email->send();

In my Signup controller I have this code:

public function signup() {
   $this->form_validation->set_rules('first_name', 'First name', 'required');
   $this->form_validation->set_rules('last_name', 'Last name', 'required');
   $this->form_validation->set_rules('email', 'Email', 'required|trim|valid_email');
   $this->form_validation->set_rules('password', 'Password', 'required|min_length[6]');
   $this->form_validation->set_rules('cpassword', 'Confirm password', 'required|matches[password]');
   $this->form_validation->set_error_delimiters('<p class="error">', '</p>');

   if ($this->form_validation->run()) {
       $first_name = $this->input->post('first_name');
       $last_name = $this->input->post('last_name');
       $email =  $this->input->post('email');
       $password = $this->input->post('password');
       $verification_key = md5($email);
       $date_created = date('Y-m-d H:i:s');
       $date_updated = date('Y-m-d H:i:s');
       $active = 0;
       // Load user model

       // If email does not already exist in the database
       // signup new user
       if (!$this->Usermodel->email_exists($email)) {
           if ($this->Usermodel->user_register($first_name, $last_name, $email, $password, $verification_key, $date_created, $date_updated, $active) && $this->Usermodel->activationEmail($first_name, $last_name, $email, $verification_key)) {

               $this->session->set_flashdata("signup_success", "Your account has just bean created. You must confirm it before you can sign in. We have send you a confirmation email at $email for this purpose.");

           } else {
               // unless sigup does not fail for whatever reason
               $this->session->set_flashdata("signup_failure", "We ware unable to create your account.");
       } else {
           // If email is already in the database
           // urge user to sign in (redirect to signup page too)
           $this->session->set_flashdata("email_exists", "The email address $email already exists in the database. Please signin.");
   } else {

Not only does the email NOT send but I get this error at signup:

Message: Missing argument 2 for Usermodel::activationEmail(), called in path/to/application/directory/ciauth/application/controllers/Signup.php on line 42 and defined

Filename: models/Usermodel.php

Line Number: 27

The sign up doAes happend, but the verification email is not send. I am not doing this from a local XAMPP/WAMP/MAMP server, but from a "live" one.
What am I doing wrong?

(This post was last modified: 03-18-2018, 05:45 AM by jreklund.)

Print the error message:

You are specifying smtp settings but sending with mail. Change protocol into smtp.
You can also delete mailpath and smtp_timeout (sometimes servers hate a too high value).
You need to specify smtp_crypto, due to the fact you are using a ssl port.

Theme © iAndrew 2016 - Forum software by © MyBB