I am trying to setup SMTP on CodeIgniter. Everything is working fine and I recieve success message on page, that email is sent without errors. But, email is not delivered.
Here is the code, that I use:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]',
'smtp_pass' => '***',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$this->load->library('email', $config);
$this->email->from('[email protected]', 'Explendid Videos');
$this->email->to('[email protected]');
$this->email->reply_to('[email protected]', 'Explendid Videos');
$this->email->subject('Explendid Video - Contact form');
$message = "Contact form\n\n";
$message .= "Name: ". $_POST['name'] . "\n";
$message .= "Phone: ". $_POST['phone'] . "\n";
$message .= "Email: ". $_POST['email'] . "\n";
$this->email->message($message);
$this->email->send();
What can be the reason, that e-mail is not actually delivered.
In Google Mail, you must allow "less secure" apps access in order for your SMTP settings to work. There are two places this setting must be enabled: The first is here: https://myaccount.google.com/ under “Connected apps & sites.”
Use the Gmail SMTP serverIf you connect using SSL or TLS, you can send mail to anyone inside or outside of your organization using smtp.gmail.com as your server. This option requires you to authenticate with your Gmail or Google Workspace account and passwords.
Change it to the following:
$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "[email protected]";
$config['smtp_pass'] = "yourpassword";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";
$ci->email->initialize($config);
$ci->email->from('[email protected]', 'Blabla');
$list = array('[email protected]');
$ci->email->to($list);
$this->email->reply_to('[email protected]', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->send();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With