Platform
Docs
Solutions
ContactLog In

Error: CodeIgniter SMTP Mail Not Working

What's Causing This Error

This error occurs due to numerous reasons.

  • Invalid SMTP configurations: The connection will not get established if the SMTP configurations provided are invalid. For example, if the email protocol, credentials, host, or port is invalid, the connection will not get established.
  • SMTP authentication is disabled: If the email sending account does not have SMTP authentication enabled, it will not work. For example, if you're using Google, the SMTP connection will not get established unless you turn on the Less Secure Sign-In.
  • Firewall issues: Sometimes, the firewall may prevent outgoing requests that can potentially affect SMTP connections.
  • Invalid connection requirements: If you have not specified SSL or TLS, the connection will not get established (depending on the SMTP provider).
  • Formatting errors: In rare cases, I've experienced errors with CodeIgniter mail with SMTP where the use of single quotes for the configuration caused issues with establishing SMTP connections.

Solution - Here's How To Resolve It

There is no proper way to fix this error. Instead, try the actions below and see which one works for you.

  • Try disabling your anti-virus guard or firewall before proceeding.
  • Visit your SMTP provider and ensure the configurations (SMTP host, port, username, and password) are valid.
  • If your email sending account requires additional configuration, make sure to provide the configuration. For example, with Google, make sure to turn on Less Secure Sign-In.
  • Use the designated TLS or SSL port per your SMTP provider's guidelines.
  • Use double quotes rather than single quotes to specify the SMTP configuration.

The snippet shown below addresses the use of double-quotes. Therefore, you may use the snippet below and see if it resolves the error.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 $config = array( 'protocol' => "smtp", // make sure this is set as SMTP to enable connections to SMTP servers, else it will send via inbuilt php mail. 'smtp_host' => "your.smtp.host", // use double-quotes'smtp_port' => YOUR-PORT (as number),'smtp_user' => "YOUR-EMAIL-ADDRESS" 'smtp_pass' => "YOUR-EMAIL-PASSWORD", 'mailtype' => "text", 'charset' => "utf-8", 'wordwrap' => true, 'wrapchars' => 50, 'crlf' => "/r/n", 'newline' => "/r/n" ); $this->load->library('email'); // load mail library $this->email->initialize($config); // initialize with smtp configs $this->email->from('YOUR-SENDER-EMAIL'); $this->email->to('YOUR-RECIPIENT-EMAIL'); $this->email->subject('YOUR-SUBJECT'); $this->email->message('YOUR-BODY'); $this->email->send(); // email sent

Other Common SMTP Errors (and Solutions)

View all errors

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Platform

Users

Content

Channels

Sending

Workflows

Preferences

Inbox

Workspaces

Observability

API Status

Changelog

© 2024 Courier. All rights reserved.