golf_backend/app/Controllers/Sendmail_controller.php
2023-05-08 10:32:05 +05:30

67 lines
2.1 KiB
PHP

<?php namespace App\Controllers;
// use App\Models\Dashboard_model;
use App\Models\Member_model;
class Sendmail_controller extends BaseController
{
public function __construct()
{
$this->session = session();
$this->MemberModel = new Member_model();
}
public function index($to,$code)
{
echo '<p>Please click your email address to verify</p>';
$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 = '<p>Please click the following link to verify your email address</p>';
$message .= '<p><a href="'.base_url().'verify_email/'.$code.'">Verify Email</a></p>';
$email->setSubject('Verify your email address');
$email->setMessage($message);
if ($email->send()) {
return 1;
} else {
return 0;
}
}
public function verify_email($verification_code)
{
// Get the user data corresponding to the verification code
$user_data = $this->MemberModel->where('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->set_flashdata('mail_success', "Your email has been verified. Please login to continue.");
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.';
}
}
}