I'm going straight to the point here. I'm trying to send an mail using codeigniter library. However, I'm not receiving any email and there are no errors shown on my code. I don't know why it doesn't work.
I've also followed the 2 step verification
and allow access to less secure apps
However when I omit the config, it send me an email which goes directly to the spam section. I don't know why it goes to spam section.
Here's my code:
public function sending_email(){
// The mail sending protocol.
$config['protocol'] = 'smtp';
// SMTP Server Address for Gmail.
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
// SMTP Port - the port that you is required
$config['smtp_port'] = '465';
// SMTP Username like. (abc@gmail.com)
$config['smtp_user'] = 'sample@gmail.com';
// SMTP Password like (abc***##)
$config['smtp_pass'] = '****';
// Load email library and passing configured values to email library
$this->load->library('email', $config);
// Sender email address
$this->email->from('sample@gmail.com', 'sample');
// Receiver email address.for single email
$this->email->to('receiver@gmail.com');
//send multiple email
//$this->email->to(abc@gmail.com,xyz@gmail.com,jkl@gmail.com);
// Subject of email
$this->email->subject('test');
// Message in email
$this->email->message('hello world!');
// It returns boolean TRUE or FALSE based on success or failure
echo $this->email->send();
}