Well as a lots of user have the same problem, I think that its a recently new issue, I read the wiki, I looking for solutions on stackoverflow like:
https://stackoverflow.com/questions/48065570/php-mailer-smtp-connect-failed-03-01-2018
and all of the ppl have the same error...suddenly PHPmailer sound like imcompatible with gmail, I tested tls, ssl, 465, 587 a lot of options and nothing works..
I also used the example from your documentation and doesnt work too,
Could you please help us? maybe Google its doing something especial with Auth or wherever...
I dont have problem with telnet, firewall, or network...this is new.
Thanks !!!
SMTP connect() failed.
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
* This uses traditional id & password authentication - look at the gmail_xoauth.phps
* example to see how to use XOAUTH2.
* The IMAP section shows how to save this message to the 'Sent Mail' folder using IMAP commands.
*/
//Import PHPMailer classes into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
require 'autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "[email protected]";
//Password to use for SMTP authentication
$mail->Password = "XXXXXX";
//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('[email protected]', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('[email protected]', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
//Section 2: IMAP
//Uncomment these to save your message in the 'Sent Mail' folder.
#if (save_mail($mail)) {
# echo "Message saved!";
#}
}
//Section 2: IMAP
//IMAP commands requires the PHP IMAP Extension, found at: https://php.net/manual/en/imap.setup.php
//Function to call which uses the PHP imap_*() functions to save messages: https://php.net/manual/en/book.imap.php
//You can use imap_getmailboxes($imapStream, '/imap/ssl') to get a list of available folders or labels, this can
//be useful if you are trying to get this working on a non-Gmail IMAP server.
function save_mail($mail)
{
//You can change 'Sent Mail' to any other folder or tag
$path = "{imap.gmail.com:993/imap/ssl}[Gmail]/Sent Mail";
//Tell your server to open an IMAP connection using the same username and password as you used for SMTP
$imapStream = imap_open($path, $mail->Username, $mail->Password);
$result = imap_append($imapStream, $path, $mail->getSentMIMEMessage());
imap_close($imapStream);
return $result;
}
2018-01-05 18:59:26 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP u36sm3970374qtc.58 - gsmtp
2018-01-05 18:59:26 CLIENT -> SERVER: EHLO localhost
2018-01-05 18:59:26 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [200.127.146.2]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2018-01-05 18:59:26 CLIENT -> SERVER: STARTTLS
2018-01-05 18:59:27 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2018-01-05 18:59:27 CLIENT -> SERVER: QUIT
2018-01-05 18:59:27
2018-01-05 18:59:27
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
This is very weird...adding:
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
but only Works if I'm logging in gmail in the browser..... so what its the problem?
You have a TLS problem, probably caused by outdated CA certificates which has affected gmail recently, exactly as described in the troubleshooting guide, reported here at least 10 times, and also many times on Stack Overflow. Search before posting.

I tested in production enviroment too and doesnt work if I not login on the browser :S
Your site's certificate has absolutely nothing to do with this. That's also mentioned in the guide, along with everything else that the error message gmail is showing you. I can't make you read the docs, but you won't fix this unless you do.
I seriusly dont understand why you are very rude in the way that you wrote...Maybe the guide its very confusing because a lot of ppl have the same error, report here and nobody give a solution.
I read the the documentation and I try many "solutions" nothings works except the mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
but only if I logging...
It's just very boring when I have to answer the same question over and over again when the answer is fully documented.
So tell me what happened when you replaced your CA certificates bundle with an updated version as the guide suggests? What happened after you did what gmail told you and logged into gmail via your browser (as mentioned in the guide)? What happened when you visited the "display unlock captcha" page, also in the guide?
Also as the guide says, setting the SMTPOptions like that will make the problem "go away", but it does not fix it, it just hides your security vulnerability.
I dont have to replaced my CA certificates because I use php 5.3.X and I have enabled the less secure app, also too for doubts I click don unlock captcha.
So I dont have other option that still use SMTPOptions as I sayed in the second comment.
Thanks anyway for your time.
That you're using PHP 5.3 (which you shouldn't be anyway as it's years out of support and contains security holes) doesn't mean that your CA certificates don't matter - they can cause validation failures in exactly the same way as other PHP versions. The only difference is that 5.3 doesn't verify by default - so you must have a non-default config that enables certificate verification in 5.3, which is a good thing.
The guide tells you how to validate your certificate chain using openssl, and that will tell you exactly what the problem is. Overall, this is not a PHPMailer problem - it's a PHP config issue caused by changes in gmail and using outdated packages (which is how CA certs are usually updated).
Enabling less secure apps has nothing to do with TLS or certificates; it only affects the authentication mechanisms available, which happen after a TLS connection has been established.
bonjour les amis j'ai un souci un peu comme celui de la haut quand je postule pour l'envoi de mail voila ce que je recois comme message d'erreur .
2018-11-05 12:17:23 SERVEUR -> CLIENT: 220 smtp.gmail.com ESMTP e66-v6sm3294672wmf.40 - gsmtp
2018-11-05 12:17:23 CLIENT -> SERVEUR: EHLO localhost
2018-11- 05 12:17:23 SERVEUR -> CLIENT: 250-smtp.gmail.com à votre service, [41.189.49.196] 250 TAILLE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
05/11/2018 12:17 : 23 CLIENT -> SERVEUR: STARTTLS
2018-11-05 12:17:23 SERVEUR -> CLIENT: 220 2.0.0 Prêt à démarrer TLS
2018-11-05 12:17:24 CLIENT -> SERVEUR: EHLO localhost
2018- 11-05 12:17:24 SERVEUR -> CLIENT: 250-smtp.gmail.com à votre service, [41.189.49.196] 250-SIZE 35882577250-8BITMIME250-AUTH LOGIN CHUNKING250 SMTPUTF8
2018-11-05 12:17:24 CLIENT -> SERVEUR: MAIL DE: zabuza225@gmail.com
2018-11-05 12:17:24 SERVEUR -> CLIENT: 530 - 5.5.1 Authentification requise. En savoir plus sur at530 5.5.1 https://support.google.com/mail/?p=WantAuthError e66-v6sm3294672wmf.40 - gsmtp
2018-11-05 12:17:24 ERREUR SMTP: Echec de la commande MAIL FROM: 530-5.5 .1 Authentification requise. En savoir plus sur530 5.5.1 https://support.google.com/mail/?p=WantAuthError e66-v6sm3294672wmf.40 - gsmtp
L'adresse d'expéditeur suivante a échoué: [email protected]: échec de la commande MAIL FROM, authentification requise. Pour plus d'informations, consultez la page https://support.google.com/mail/?p=WantAuthError e66-v6sm3294672wmf.40 - gsmtp, 530,5.5.1SMTP erreur de serveur: échec de la commande MAIL FROM Détail: authentification requise. Pour plus d'informations, consultez la page https://support.google.com/mail/?p=WantAuthError e66-v6sm3294672wmf.40 - gsmtp Code SMTP: 530 Informations SMTP supplémentaires: 5.5.1
Le message n'a pas pu être envoyé. Erreur de publipostage: l'adresse d'expéditeur suivante a échoué: [email protected]: échec de la commande MAIL FROM, authentification requise. Pour plus d'informations, consultez la page https://support.google.com/mail/?p=WantAuthError e66-v6sm3294672wmf.40 - gsmtp, 530,5.5.1SMTP erreur de serveur: échec de la commande MAIL FROM Détail: authentification requise. Pour plus d'informations, consultez la page https://support.google.com/mail/?p=WantAuthError e66-v6sm3294672wmf.40 - gsmtp Code SMTP: 530 Informations SMTP supplémentaires: 5.5.1SMTP Erreur de serveur: Échec de la commande MAIL FROM: Authentification requise. Pour plus d'informations, consultez la page https://support.google.com/mail/?p=WantAuthError e66-v6sm3294672wmf.40 - gsmtp Code SMTP: 530 Informations SMTP supplémentaires: 5.5.12018-11-05 12:17:24 CLIENT -> SERVEUR : QUIT
2018-11-05 12:17:24 SERVEUR -> CLIENT: 221 2.0.0 connexion de fermeture e66-v6sm3294672wmf.40 - gsmtp
@githubfranci SVP lire les messages, suivez les liens. Utiliser l'exemple gmail et utilisez votre id/pass.
Most helpful comment
I seriusly dont understand why you are very rude in the way that you wrote...Maybe the guide its very confusing because a lot of ppl have the same error, report here and nobody give a solution.
I read the the documentation and I try many "solutions" nothings works except the mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
but only if I logging...