We're talking about the certificates of your email server. If you are using some sort of managed hosting service, it's usually a different server than the one your files are.
For example in Dreamhost you could connect to the email server via mail.yourdomain.com or something like sub4.mail.dreamhost.com that server is independent of your files one, and the certificate is different too.
The problem (from what you posted here), is that you try to connect to mail.yourdomain.com but the email server's certificate is for mail.yourprovider.com which is different. With the modification I told you, you disable certificate verification, ie, it should work even if the domain is different. But the solution is not to disable it, but to provide a valid certificate, ie, that your email server offers a certificate on behalf of mail.yourdomain.com
Wordpress may have disabled certificate verification in their code and that's maybe the reason why it works there.
Also, I thought we were talking about emails not being sent, if you have another issues, please explain too, because email has nothing to do with database connections.