Sometimes phpmailer fails sending through SMTP with TLS. I’ve set up a test with same smtp server (smtp.office365.com) and credentials. Sometimes it fails with "SMTP NOTICE: EOF caught while checking if connected". I’ve tried updating with longer timeout and also tried changing the options with
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)
But that’s not helping either. Sometimes it sends without problem and sometimes it doesn’t.
Server is running php 5.5, and I’ve tried with newest phpmailer version but that’s not helping.
When I test same code on another server with newer php version it always works, but what can be done to also make it work on php 5.5 if that’s the issue.
2
Answers
It’s very likely that your server running PHP 5.5 (which is really, really old, outdated, and probably unsafe) also has outdated CA certificate bundles. When you connect to Outlook, you may be connected to one of many of their servers, which may have certificates of varying ages signed by different CAs, and your client may not be able to verify them all with your outdated CA bundle, so the solution there should be to update your CA certs.
Having said that, this should be largely suppressed by disabling verification, as you have tried (though that is generally something you should avoid), however, that only disables one aspect of TLS, and it’s possible that you may be connecting to servers which don’t support the older TLS protocols your client is probably capable of handling.
Ultimately, the best solution is to update your PHP version.
Set this in your code:
And see exactly what the error is.
I had the same problem where some times it worked and some times it didn’t and I had to update file: class.smtp.php function startTLS() to use STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT