title: I cannot properly configure PHPMailer
body: <p>I have spent the last four hours reading examples, watching YouTube videos etc and I cannot for the life of me get an email to send.  I have tried using a G-mail account with the settings changed to allow for less secure apps and also a privately hosted email address from my business.</p>
  <p>I loaded PHPMailer with composer</p>
  <p>When I use the following code which is literally the example from PHPMailer's github page, I get the errors listed below.</p>
  <pre><code>  &lt;?php
  
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    use PHPMailer\PHPMailer\Exception;
  
    require_once 'vendor/autoload.php';
  
    $mail = new PHPMailer(true);
  
    try {
        //Server settings
        $mail-&gt;SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
        $mail-&gt;isSMTP();                                            //Send using SMTP
        $mail-&gt;Host       = 'smtp.gmail.com';                       //Set the SMTP server to send through
        $mail-&gt;SMTPAuth   = true;                                   //Enable SMTP authentication
        $mail-&gt;Username   = 'my gmail email here';                  //SMTP username
        $mail-&gt;Password   = 'my gmail password here';               //SMTP password
        $mail-&gt;SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
        $mail-&gt;Port       = 465;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
    
        //Recipients
        $mail-&gt;setFrom('my gmail email address', 'Mailer');
        $mail-&gt;addAddress('different email address', 'Joe User');     //Add a recipient
  
  
        //Content
        $mail-&gt;isHTML(true);                                  //Set email format to HTML
        $mail-&gt;Subject = 'Here is the subject';
        $mail-&gt;Body    = 'This is the HTML message body &lt;b&gt;in bold!&lt;/b&gt;';
        $mail-&gt;AltBody = 'This is the body in plain text for non-HTML mail clients';
    
        $mail-&gt;send();
        echo 'Message has been sent';
    } catch (Exception $e) {
        echo &quot;Message could not be sent. Mailer Error: {$mail-&gt;ErrorInfo}&quot;;
    }
  </code></pre>
  <p>This is the error message that I get:
  2021-08-09 20:04:25 SMTP ERROR: Failed to connect to server: (0)
  SMTP connect() failed. <a href="https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" rel="nofollow noreferrer">https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting</a>
  Message could not be sent. Mailer Error: SMTP connect() failed. <a href="https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" rel="nofollow noreferrer">https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting</a></p>
  <p>I am 100% sure that the email addresses and passwords are correct and listed in the proper locations.</p>
  <p>Does anyone know what is going on or what I can do to fix?</p>
  <p>I am so desperate I am about to just switch programming languages because this is the most insanely complicated thing I have ever came across!</p>
  <p>Thanks so much to anyone that has a solution or tips!</p>
  <p>PS I am currently using localhost... I will answer any questions that you need answered Thanks!!!</p>
  <p>UPDATE &gt;&gt;&gt;
  When I change to this line</p>
  <pre><code>$mail-&gt;SMTPDebug = SMTP::DEBUG_CONNECTION; 
  </code></pre>
  <p>I get this output:</p>
  <p>2021-08-09 21:02:10 Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array()
  2021-08-09 21:02:10 Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed [C:\xampp\htdocs\sheri\vendor\phpmailer\phpmailer\src\SMTP.php line 388]
  2021-08-09 21:02:10 Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [C:\xampp\htdocs\sheri\vendor\phpmailer\phpmailer\src\SMTP.php line 388]
  2021-08-09 21:02:10 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) [C:\xampp\htdocs\sheri\vendor\phpmailer\phpmailer\src\SMTP.php line 388]
  2021-08-09 21:02:10 SMTP ERROR: Failed to connect to server: (0)
  SMTP connect() failed. <a href="https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" rel="nofollow noreferrer">https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting</a>
  Message could not be sent. Mailer Error: SMTP connect() failed. <a href="https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting" rel="nofollow noreferrer">https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting</a></p>