session = session(); $this->MemberModel = new Member_model(); } public function index($to,$code,$return) { $email = \Config\Services::email(); $email->setFrom('suseendhiran.1702117@srit.org', 'suseendhiran'); $email->setTo($to); // $email->setCC('another@another-example.com'); // $email->setBCC('them@their-example.com'); $message = '

Please click the following link to verify your email address

'; $message .= '

Verify Email

'; $email->setSubject('Verify your email address'); $email->setMessage($message); if ($email->send()) { if ($return == 1) { $this->session->setTempdata('mail_success', "Please check your mail to verify",3); // return redirect()->to(base_url()); } else { return 0; } } else { return 0; } } public function verify_email($verification_code) { // Get the user data corresponding to the verification code $user_data = $this->MemberModel->where('md5(verification_code)', $verification_code)->find(); if($user_data) { // Update the users status // $update_data = $this->MemberModel->update_status($user_data['id']); $data['is_email_verified'] = 1; $update_data = $this->MemberModel->where('id', $user_data[0]['id'] )->set($data)->update(); if($update_data) { // Show success message $this->session->setTempdata('mail_success', "Email verification sucessfully.",3); return redirect()->to(base_url()); } else { // Show error message echo 'Error in verifying email. Please try again.'; } } else { // Show error message echo 'Invalid verification code.'; } } }