0

I have tried and developed an application with mail sending functionality in CodeIgniter. Early mail worked, but mail is not sending. There are no errors reported. It says Mail Sending Successfully, but I haven't received mail.

Controller Code:

public function mail() { 
     $from_email = "tamilshanmugamit460@gmail.com";

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

     $this->email->from($from_email, 'Your Name'); 
     $this->email->to($from_email);
     $this->email->subject('Email Test'); 
     $this->email->message('Testing the email class.'); 

     //Send mail 
     if($this->email->send()) 
     echo "Email sent successfully."; 
     else 
     echo "Error in sending Email.";
  }
AuxTaco
  • 4,883
  • 1
  • 12
  • 27
Tamilselvan S
  • 23
  • 1
  • 8

1 Answers1

0

Use this method hope it will help you

Email configuration

$this->load->library('email');
$config['protocol']    = 'smtp';
$config['smtp_host']    = 'ssl://smtp.gmail.com';
$config['smtp_port']    = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = "user-email";
$config['smtp_pass'] = "password";
$config['charset']    = 'utf-8';
$config['newline']    = "\r\n";
$config['mailtype'] = 'html'; 
$this->email->initialize($config);

Email sending code

$this->email->from('your-email', 'Name');
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send()
Danish Ali
  • 2,354
  • 3
  • 15
  • 26