Hello,

We are sending email using these settings:

$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = 465;
$config['protocol'] = 'smtp';
$config['mailtype'] = 'html';
$config['smtp_user'] = 'email@gmail.com';
$config['smtp_pass'] = 'password';
$config['smtp_timeout'] = 40;

Thats ok it works. For few days. Later it stops sending. THen we go to gmail acount in web interface to login. It is not able to login, it asks to enter capcha letters.

Then after logging in to web interface, PHP also started sendign emails.

How could this be related? Anyone had same problem?

Dani AI

Generated

Short summary of what's happening and why it repeats

Gmail is doing automated, risk‑based sign‑in protection: when a script or a different IP/host logs in repeatedly it can flag the activity and require an interactive proof (CAPTCHA / web login) before it will accept SMTP/IMAP access again. That explains why things work after you log into the web interface but then later fail again. (stackoverflow.com)

Immediate troubleshooting steps (do these in order)

  • Use a dedicated sending account (not a personal inbox) so security events don’t affect your main account.
  • Follow ’s app‑password route (app passwords require 2‑Step Verification). That often fixes basic auth scenarios. ()
  • From the server where PHP runs, open the Google unlock page to register that IP/session (this lets Google trust that machine for a short window). If you cannot browse from the server, create an SSH SOCKS proxy or use a browser on the server to do the same. (nextcloud-mail.readthedocs.io)
  • Test the SMTP TLS handshake from the server so you can separate networking issues from auth problems:
openssl s_client -crlf -starttls smtp -connect smtp.gmail.com:587

If the TLS connect fails, fix that before chasing Google auth. (Keep connections infrequent and reuse a single connection when possible.)

Longer‑term fixes (recommended)

  • Move away from plain password SMTP to OAuth2 or the Gmail API for programmatic sending; Google now prefers OAuth flows for app access. If you own the app, get a refresh token and authenticate with OAuth2 instead of password auth. (developers.google.com)
  • Or use a transactional SMTP provider (reliable delivery, APIs, and fewer interactive security blocks). For small volumes Mailgun or Postmark are common choices with developer/free entry tiers and clear documentation. They remove the “human must click CAPTCHA” problem and scale better than a personal Gmail account. (mailgun.com)

Notes tied to the thread

  • ’s suggestion about trying different ports can sometimes help for connectivity issues, but the root here is Google’s security checks — changing ports alone won’t stop CAPTCHA locks.
  • was right to flag volume as a reason for switching providers later; even if you’re under Gmail limits today, account‑based blocks happen because of security signals, not just send count.

If reliable, unattended sending is required, the fastest stable route is a transactional provider or OAuth2/Gmail API rather than a personal SMTP login.

Recommended Answers

All 9 Replies

Generate an application password and use that to sign in through SMTP:

thanks, will try later.

I tried it, but after some time agian webmail was asking to enter from captcha and sending emails stopped working even with generated application password.

For such simple task so long solution. I dont get it.

Maybe you can recommend some other email sending service free and withot those nonsenses?

How many e-mails are being sent? It sounds like gmail has rumbled the fact that this is not just personal mail, but commercial. If you are sending mass e-mails you are gonna have to pay......

no, we are just currently tring to send like 3-4 emails per day. In near future maybe it will grow to only 10 emails per day :) and if it wants money, then why it should not throw some message that it needs money?

Making email server on ubuntu there is no quick and easy way as my co-worker said. But its 2013 - there should be enough mail services I think.

Member Avatar for Member #949455

For such simple task so long solution. I dont get it.

Read this and see if it may helps (not sure of it but it might):

Thanks, I read it and I see the answer:

Are you able to log in to the Gmail web interface?
Visit http://mail.google.com to log in to Gmail. If you see a CAPTCHA (a security image with distorted letters), you'll need to log in before you can enable IMAP access. If you're locked out of Gmail, please wait one hour and log in to Gmail again.

But we know it - when we enter the capthca, then ok. After some time it requests cat[pcha againg and php aplication cannot send it again. We don't want to cehck everyday gmail interface if there is captcha requested.

Member Avatar for Member #949455

But we know it - when we enter the capthca, then ok. After some time it requests cat[pcha againg and php aplication cannot send it again. We don't want to cehck everyday gmail interface if there is captcha requested.

Try to change your port from

$config['smtp_port'] = 465;

to

$config['smtp_port'] = 25;

This is from the link:

If you tried configuring your SMTP server on port 465 (with SSL) and port 587 (with TLS), but are still having trouble sending mail, try configuring your SMTP to use port 25 (with SSL). 

thank you, I will try

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.