0
$mail = new PHPMailer(true);
        try {
            $mail->SMTPDebug = 2;                                 
            $mail->isSMTP();                                      
            $mail->Host = 'smtp.gmail.com';  
            $mail->SMTPAuth = true;                               
            $mail->Username = 'email@gmail.com';                 
            $mail->Password = 'password';                           
            $mail->SMTPSecure = 'tls';                            
            $mail->Port = 587;                                    
            //Recipients
            $mail->setFrom('email@gmail.com', 'name');
            $mail->addAddress('email@gmail.com', 'Joe User');     

            //Content
            $mail->isHTML(true);                                  
            $mail->Subject = "A subject";
            $mail->Body    = "The body";

            $mail->send();
            echo 'Message has been sent';
        } catch (Exception $e) {
            echo 'Message could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        }

With the above code I get the following error

2020-09-04 04:59:49 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP t24sm4345848pgo.51 - gsmtp
2020-09-04 04:59:49 CLIENT -> SERVER: EHLO localhost
2020-09-04 04:59:50 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [27.34.104.219]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250 SMTPUTF8
2020-09-04 04:59:50 CLIENT -> SERVER: STARTTLS
2020-09-04 04:59:50 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS SMTP Error: Could not connect to SMTP host.
2020-09-04 04:59:50 CLIENT -> SERVER: QUIT
2020-09-04 04:59:50
2020-09-04 04:59:50 SMTP Error: Could not connect to SMTP host.
Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.

Please help

M. Eriksson
  • 13,450
  • 4
  • 29
  • 40
tisa
  • 1
  • 1
  • can you login froma browser to that email account? – Chris Richardson Sep 04 '20 at 05:13
  • https://stackoverflow.com/questions/3477766/phpmailer-smtp-error-could-not-connect-to-smtp-host check this link for your answers – BhAvik Gajjar Sep 04 '20 at 05:48
  • When you run into a problem like this, your first reaction should be to *read the docs* rather than posting a question on here. In this case it should not have taken you long to find a link to the PHPMailer troubleshooting guide that discusses how to identify and deal with [this exact issue](https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#certificate-verification-failure). – Synchro Sep 04 '20 at 06:44

0 Answers0