I searched for this fix for quite some time. The popular WordPress Post SMTP plugin was returning “Warning: connected to mydomain.com instead of smtp.gmail.com” and not sending emails via any SMTP server. I checked DNS, telnet from command line and a bunch of other things until I came across this setting.
Cpanel has some settings that were restricting SMTP to only a few users/processes, which was causing this error. Changing that setting in TweakSettings and making sure port 465 (in my case, but whatever port you’re using) was enabled in ConfigServer Firewall aka CSF for both TCP and UDP was the solution for me.
These fixes/settings aren’t just for the Post SMTP plugin, it may apply to many other WordPress SMTP plugins or being able to use your own PHP or other scripts to send mail through Google’s SMTP server and your Gmail or G Suite mail accounts.
If you don’t have WHM access (which many on a hosting account don’t) you can send this page link to your hosting provider and ask them to change the setting. They may or may not, but it doesn’t hurt to ask.