title: PHPMailer SMTP Error: Could not connect to SMTP host
body: <p>Having a strange problem with PHPMailer where it's showing an SMTP connection error, as seen below. What could cause this? It works when I use the Gmail SMTP server, and also works with the local mail function. Roundcube on the server sends fine. It just seems to be PHPMailer. All settings are correct, to the best of my knowledge. It's using TLS and I've tried different ports. The correct ports show the following error:</p>
  
  <pre><code>2016-05-05 21:58:47 Connection: opening to mail.myserver.com:587, timeout=300, options=array (
                                        )
  2016-05-05 21:58:47 Connection: opened
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $data is ""
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $str is  "220 sys.myserver.com ESMTP Exim 4.72 Thu, 05 May 2016 17:58:50 -0400
                                        "
  2016-05-05 21:58:52 SERVER -&gt; CLIENT: 220 sys.myserver.com ESMTP Exim 4.72 Thu, 05 May 2016 17:58:50 -0400
  2016-05-05 21:58:52 CLIENT -&gt; SERVER: EHLO localhost
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $data is ""
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $str is  "250-sys.myserver.com Hello ***********]
                                        "
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $data is "250-sys.myserver.com Hello cpc68331-cdif16-2-0-cust906.5-1.cable.virginm.net [86.3.207.139]
                                        "
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $str is  "250-SIZE 52428800
                                        "
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $data is "250-sys.myserver.com Hello cpc68331-cdif16-2-0-cust906.5-1.cable.virginm.net [86.3.207.139]
                                        250-SIZE 52428800
                                        "
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $str is  "250-PIPELINING
                                        "
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $data is "250-sys.myserver.com Hello ***************************]
                                        250-SIZE 52428800
                                        250-PIPELINING
                                        "
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $str is  "250-AUTH PLAIN LOGIN
                                        "
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $data is "250-sys.myserver.com Hello ****************************]
                                        250-SIZE 52428800
                                        250-PIPELINING
                                        250-AUTH PLAIN LOGIN
                                        "
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $str is  "250-STARTTLS
                                        "
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $data is "250-sys.myserver.com Hello ******************]
                                        250-SIZE 52428800
                                        250-PIPELINING
                                        250-AUTH PLAIN LOGIN
                                        250-STARTTLS
                                        "
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $str is  "250 HELP
                                        "
  2016-05-05 21:58:52 SERVER -&gt; CLIENT: 250-sys.myserver.com Hello ***************]
                                        250-SIZE 52428800
                                        250-PIPELINING
                                        250-AUTH PLAIN LOGIN
                                        250-STARTTLS
                                        250 HELP
  2016-05-05 21:58:52 CLIENT -&gt; SERVER: STARTTLS
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $data is ""
  2016-05-05 21:58:52 SMTP -&gt; get_lines(): $str is  "220 TLS go ahead
                                        "
  2016-05-05 21:58:52 SERVER -&gt; CLIENT: 220 TLS go ahead
  2016-05-05 21:58:52 SMTP Error: Could not connect to SMTP host.
  2016-05-05 21:58:52 CLIENT -&gt; SERVER: QUIT
  2016-05-05 21:58:53 SMTP -&gt; get_lines(): $data is ""
  2016-05-05 21:58:53 SMTP -&gt; get_lines(): $str is  "����221 sys.myserver.com closing connection
                                        "
  2016-05-05 21:58:53 SMTP -&gt; get_lines(): $data is "����221 sys.myserver.com closing connection
                                        "
  2016-05-05 21:58:53 SMTP -&gt; get_lines(): $str is  ""
  2016-05-05 21:58:53 SERVER -&gt; CLIENT: ����221 sys.myserver.com closing connection
  2016-05-05 21:58:53 SMTP ERROR: QUIT command failed: ����221 sys.myserver.com closing connection
  
  
  ----------
  
  
  2016-05-05 21:58:53 Connection: closed
  2016-05-05 21:58:53 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
  {"success":1,"id":"3391"}
  </code></pre>