I’m having trouble setting up SMTP email with Gmail in my CodeIgniter project. Every time I try to send an email, I get authentication errors even though my Gmail account seems to be working fine.
Here’s the error message I keep getting:
220 mx.google.com ESMTP c25sm891456gha.41
hello: 250-mx.google.com at your service, [95.142.67.203]
250-SIZE 35651584
250-8BITMIME
250-AUTH LOGIN PLAIN
250-ENHANCEDSTATUSCODES
250 PIPELINING
Failed to authenticate password. Error: 454 4.7.0 Cannot authenticate due to temporary system problem. Try again later. c25sm891456gha.41
from: 530-5.5.1 Authentication Required.
530 5.5.1 Authentication Required. c25sm891456gha.41
The following SMTP error was encountered: 530-5.5.1 Authentication Required.
I’ve checked my Gmail account multiple times and I can log in without any issues. I’ve also disabled two-factor authentication temporarily to test but still no luck.
Someone mentioned that PHP’s built-in mail() function doesn’t work well with Gmail SMTP. Is this accurate? Should I consider using a different mail library like PHPMailer or SwiftMailer instead of CodeIgniter’s built-in email class?
Any suggestions or working examples would be really helpful. I’m pretty stuck on this one.
You’re using your regular Gmail password instead of an app-specific password. Google’s tightened security for SMTP access from third-party apps, even without two-factor auth enabled. Generate an app password in your Google account security settings and use that instead. Also enable “Less secure app access” in Gmail security settings (though Google’s phasing this out). Had the same problem last year - switching to app passwords fixed it instantly. CodeIgniter’s email class works great with Gmail once you get the auth right. No need to switch to PHPMailer unless you want to.
That error’s usually bad SMTP settings, not auth problems. Check you’re using port 587 with TLS or port 465 with SSL - Google throws that temp error when the connection isn’t encrypted right. Make sure you’ve got smtp.gmail.com as your server and protocol set to ‘smtp’, not ‘mail’. I’ve seen this tons of times when people mix up ports and encryption. Your email.php config needs to match Gmail’s requirements exactly.
gmail’s acting up with codeigniter’s email class lately. update your useragent string in the email config - google sometimes blocks older useragents. also make sure your from_email matches the gmail account you’re authenticating with. mismatched sender addresses will fail authentication even if your password’s right.