Monday, March 14, 2022

[FIXED] Codeigniter email send but not received

Issue

I am using CodeIgniter to send emails it showing me success message "Your Email Send is Successful" but I am not receiving email on my account.Is it a server problem, I am stuck with this problem for many days.

        $name       = post('name');
        $from_email = post('from_email');
        $to         = post('to');
        $subject    = post('subject');
        $msg        = post('msg');


        $this->load->library('email');

        $this->email->from($from_email, $name);
        $this->email->to($to);

        $this->email->subject($subject);
        $this->email->message($msg);

        $result = $this->email->send();

        if ($result) 
        {
            $msg = "Your Email Send is Successfully";
            $this->session->set_flashdata('success',$msg);
            redirect('users','refresh');
        }
        else
        {
            $msg = "Error! Can not Send Email";
            $this->session->set_flashdata('error', $msg);
            redirect('users','refresh');
        }

Solution

You can try this:

public function send_mail(){
    $this->load->library('email');
    $to_email = 'abc@gmail.com';
    $from_email = 'xyz@gmail.com';
    
    $config = array(
                    'charset' => 'utf-8',
                    'wordwrap' => TRUE,
                    'mailtype' => 'html'
                );
    
    $this->email->initialize($config);
    
     $this->email->from($from_email);
                $this->email->to($to_email);
                $this->email->subject('Test mail send');
                $this->email->message('Test Mail');
    
        if($this->email->send()){
            echo "send";
        }else{
            echo "error";
        }
}


Answered By - Shabbirhasan Nandoliya

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.