Nxt Invent Solutions
Nxt Invent Solutions

Reputation: 51

sending verification email via SMTP using gmail SMTP server failed in codeigniter

I am trying to send a registration verification email to my new user via Gmail SMTP. user data is successfully saved to the database but email is not sent to the user email ID. I am working on localhost

here is my code

$subject = "Please verify email for login";
            $message = "
                        <p>Hi " . $this->input->post('hospital_name') . "</p>
                        <p>This is email verification mail from Codeigniter Login Register system. For complete registration process and login into system. 
                        First you want to verify you email by click this <a href='" . base_url() . "register/verify_email/" . $verification_key . "'>link</a>.</p>
                        <p>Once you click this link your email will be verified and you can login into system.</p>
                        <p>Thanks,</p>
                        ";
            $config  = array(
                'protocol' => 'smtp',
                'smtp_host' => 'tls://smtp.googlemail.com',
                'smtp_port' => 587,
                'smtp_user' => '****',
                'smtp_pass' => '****',
                'mailtype' => 'html',
                'charset' => 'iso-8859-1',
                'wordwrap' => TRUE
            );
            $this->load->library('email', $config);
            $this->email->set_newline("\r\n");
            $this->email->from('****');
            $this->email->to($this->input->post('hospital_email'));
            $this->email->subject($subject);
            $this->email->message($message);
            if ($this->email->send()) {
                $this->session->set_flashdata('message', 'Check in your email for email verification mail');
                redirect('register');
            }else{
                $this->session->set_flashdata('message', 'something wrong');
            }

Upvotes: 0

Views: 193

Answers (1)

Aashish gaba
Aashish gaba

Reputation: 1776

There could be a possibility that there might be something wrong with the code and it would be throwing some error. Did you check in the session, what is the message you're receiving?

If there's an error, try checking what the error could possibly be. You may check the error by using the below code.

if($this->email->send()) {
    echo 'Your Email has successfully been sent.';
}
else{
    show_error($this->email->print_debugger());
}

Upvotes: 1

Related Questions