Answers.Body: <p>I had to go this far...</p>
  
  <pre><code>$this-&gt;_socket_options = array('ssl' =&gt; array('verify_peer'=&gt;false,'verify_peer_name'=&gt;false,'allow_self_signed'=&gt;true));
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-12T13:05:31.993Z
Answers.Text: FWIW, if you are connecting to well known third party mail provider, then it's highly likely that they have their certificates set up properly and you shouldn't need to disable peer verification.
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-07T00:14:50.127Z
Answers.LastActivityDate: 2016-04-07T00:14:50.127Z
Answers.UserDisplayName: Matt
Answers.Body: <p>If you are connecting to well known third party mail provider, then it's highly likely that they have their certificates set up properly and <strong><em>you shouldn't need to disable peer verification</em></strong>.</p>
  
  <p>Check two things:</p>
  
  <ol>
  <li><p>As it mentions on the <em>Settings - Outbound Mail</em> form, 'if the server uses SSL, add "ssl://" to the beginning of the server name'.</p></li>
  <li><p>Check what port you are using: "The most common SMTP port possibilities are 25, 465, and 587".</p></li>
  </ol>
  
  <p>And if the above does not resolve the issue, verify that the hosting environment's CA chain is up to date, since that will also trigger this problem.</p>
  
  <p><em>Note: In the case of Mandrill, even though the <a href="https://mandrillapp.com/settings" rel="nofollow noreferrer">https://mandrillapp.com/settings</a> page specified port 587, ssl only worked on port 465 (as explainined in <a href="https://mandrill.zendesk.com/hc/en-us/articles/205582177-Does-Mandrill-support-SSL-" rel="nofollow noreferrer">this mandrill knowledge base article</a>).</em></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-30T02:02:44.000Z
Answers.Text: 3. verify that the hosting environment's CA chain is up to date, since that will also trigger this problem
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-30T02:03:25.173Z
Answers.Text: PS. Yours is the correct answer, but the one recommending to disable peer verification has lots of votes 
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-30T02:15:57.230Z
Answers.Text: Plus a zillion for not disabling peer verification! To speak directly to an example comment above our cert, ports, etc are set up properly and we have never had an issue connecting with Sparkpost using php 5.6.3.
Answers.UserDisplayName: Eli Lisseck
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-31T14:26:03.553Z
Answers.Text: @chris and eli - might want to consider voting up the comments in the wrong answer as well so they are above the comment fold to help others.
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-19T20:44:39.637Z
Answers.Text: @EliLisseck how are you connecting to Sparkpost? I'm trying to figure out why it's not working for us. We're using Sparkpost, Let's Encrypt, and the PESC Sparkpost extension. The extension builders say it's a core Civi issue: https://github.com/proexchange/com.pesc.sparkpost/issues/22
Answers.UserDisplayName: herb
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-19T20:56:04.833Z
Answers.Text: @herb we are connecting via the Sparkpost API using civiCRM 4.7.15 with the Cividesk sparkpost extension (rather than pesc). There is a post somewhere about the comparison. We are on PHP 5.6.30 (mistype earlier) and it seems to be working fine. Our SSL cert is with GoDaddy. We are using their premium EV cert to get our name in the green box :). We've got email and DKIM verified. Hope that is helpful.
Answers.UserDisplayName: Eli Lisseck
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-22T15:06:06.177Z
Answers.LastActivityDate: 2017-03-31T14:25:12.490Z
Answers.LastEditDate: 2017-03-31T14:25:12.490Z
Answers.UserDisplayName: michaelmcandrew
Answers.Body: <p>Seems there is some work in progress to attach this on <a href="https://issues.civicrm.org/jira/browse/CRM-18408" rel="nofollow noreferrer">CRM-18408
  SMTP connection via SSL and TLS in PHP 5.6</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-19T20:30:34.917Z
Answers.LastActivityDate: 2017-05-19T20:30:34.917Z
Answers.UserDisplayName: Francesc Bassas i Bullich
Answers.Body: <p>PHP5.6 has <a href="http://php.net/manual/en/migration56.openssl.php" rel="nofollow noreferrer">enabled peer verification by default from 5.6.x</a>. The most likely cause of this issue is that <strong>the SMTP server's SSL cert does not validate against the certs available to the hosting environment</strong>.</p>
  
  <p>So, on PHP5.6+, an SMTP connection via SSL and TLS will fail in CiviCRM <strong><em>if the certificates are not peer verified</em></strong>. This is an issue either with the SMTP provider or your hosting environment's CA chain.</p>
  
  <p>It is recommended instead to <strong>resolve the underlying issues with your hosting/SMTP service</strong>, but if you want to connect to a server with a self signed certificate (for example) you can patch CiviCRM to bypass this verification. </p>
  
  <p>Change in packages/Net/SMTP.php</p>
  
  <p>line <code>$this-&gt;_socket_options = $socket_options;</code></p>
  
  <p>to <code>$this-&gt;_socket_options = array('ssl' =&gt; array('verify_peer_name' =&gt; false));</code></p>
  
  <p>Updated: I have updated the comment here since the summary in the <a href="http://php.net/manual/en/migration56.openssl.php" rel="nofollow noreferrer">ref link</a> has also been updated to include:</p>
  
  <blockquote>
    <p>While not recommended in general, it is possible to disable peer certificate verification for a request by setting the verify_peer context option to FALSE, and to disable peer name validation by setting the verify_peer_name context option to FALSE.</p>
  </blockquote>
  
  <p>The above works around the problem with SMTP failure however it is better to ensure the server is set up with valid SSL certificate and configurations.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-07T10:11:35.313Z
Answers.Text: Are you sure all SMTP using TLS will fail, or just those using self-signed certificates which fail peer validation? Or hosting environments with outdated CA on the server.
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-11T10:50:25.453Z
Answers.Text: Works for me with SMTP via GMail. Thanks!
Answers.UserDisplayName: Christian Wach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-05T19:18:27.513Z
Answers.Text: I just ran into this as well. Should we be pushing to get this into core?
Answers.UserDisplayName: lcdservices
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-09-26T17:52:31.870Z
Answers.Text: Same here, ran into this issue with MailGun.  The above fixed it for me.
Answers.UserDisplayName: Alan Fuller
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-16T15:08:28.647Z
Answers.Text: With CiviCRM 4.7.15 and Joomla, I had to apply the single line patch to make this work with PHP 5.6, connecting to Sparkpost. Confused why this is still an outstanding issue after almost a year?
Answers.UserDisplayName: tabletguy
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-16T06:53:04.683Z
Answers.Text: Ditto here (CiviCRM 4.7.17/Joomla and PHP 5.6) - why is this not part of core? Been patching every silly CiviCRM upgrade ... sigh.
Answers.UserDisplayName: MtnPavlas
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-22T14:50:49.383Z
Answers.Text: "Since php has enabled peer verification by default from 5.6.x, all the SMTP connection via SSL and TLS will fail in CiviCRM." <-- Not true! If the certificates have been set up properly peer verification should pass.
Answers.UserDisplayName: michaelmcandrew
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-30T02:06:41.003Z
Answers.Text: IMO this answer is bad advice (telling people to disable builtin security functionality to avoid hearing about issues in the hosting / SMTP environment). Since it has lots of upvotes, I've modified it to nudge people to a better solution, without wholesale rewriting the answer. I recommend people use Michael's solution instead.
Answers.UserDisplayName: Chris Burgess
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-26T04:56:30.647Z
Answers.Text: Can anyone elaborate on what I need to do to solve this problem?  I am running CiviCRM 4.7.18 on Drupal 7, newly installed Ubuntu 16.04 running php 5.6.x.  I am getting the error:
  
  Failed to connect to tls://smtp.sparkpostmail.com:587 [SMTP: Failed to connect socket: (code: -1, response: )]
  
  Yes, we are connecting to sparkpost.  I tried prepending tls:// to the host as well as without.  None of my other web apps - including drupal itself - have a problem with 5.6.
Answers.UserDisplayName: Rob Brandt
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-30T13:34:15.810Z
Answers.Text: We have tried to actively and passively solve this error with our mail provider, but we have always had the same answer saying that for its part everything was fine and that we should to deactivate this option by code.
Answers.UserDisplayName: Francesc Bassas i Bullich
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-06T16:26:17.863Z
Answers.LastActivityDate: 2017-03-30T02:00:28.480Z
Answers.LastEditDate: 2017-03-30T02:00:28.480Z
Answers.UserDisplayName: Guanhuan
Body: <p>Just want to throw this question here so the answers can be easily found by people who met similar problems.</p>
  
  <p>Problem came up when we were trying to test some new mailing services with CiviCRM 4.7, we kept getting "connection refused" errors and other similar messages with different protocols and ports entered in outbound mail settings.</p>
  
  <p>The environment we have: Ubuntu 14.04, php 5.6, Drupal 7.3.x, CiviCRM 4.7.x.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-04-07T10:12:19.820Z
Comments.Text: A [duplicate over here](http://civicrm.stackexchange.com/questions/9467/outbound-mail-fails-after-upgrading-to-4-7-1?lq=1)?
Comments.UserDisplayName: Chris Burgess
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-30T02:08:55.563Z
Comments.Text: Disabling SSL peer verification is, to me, like taking the bulb out of a warning light to "fix" a problem with your engine. Please get the underlying issue fixed instead 
Comments.UserDisplayName: Chris Burgess
Tags: <smtp>
Title: SMTP connection failing problem
ThreadText: # SMTP connection failing problem
  
  (Asked by: username_0 on 2016-04-06)
  
  Just want to throw this question here so the answers can be easily found by people who met similar problems.
  
  Problem came up when we were trying to test some new mailing services with CiviCRM 4.7, we kept getting "connection refused" errors and other similar messages with different protocols and ports entered in outbound mail settings.
  
  The environment we have: Ubuntu 14.04, php 5.6, Drupal 7.3.x, CiviCRM 4.7.x.
  
  **Tags:** smtp
  
  > **Comments:**
  > **username_1**: A [duplicate over here](http://civicrm.stackexchange.com/questions/9467/outbound-mail-fails-after-upgrading-to-4-7-1?lq=1)?  
  > **username_1**: Disabling SSL peer verification is, to me, like taking the bulb out of a warning light to "fix" a problem with your engine. Please get the underlying issue fixed instead   
  
  ---
  
  ## 4 answers
  
  ### Answer by username_0 on 2016-04-06. Score: 15 | Accepted answer
  
  PHP5.6 has [enabled peer verification by default from 5.6.x](http://php.net/manual/en/migration56.openssl.php). The most likely cause of this issue is that **the SMTP server's SSL cert does not validate against the certs available to the hosting environment**.
  
  So, on PHP5.6+, an SMTP connection via SSL and TLS will fail in CiviCRM ***if the certificates are not peer verified***. This is an issue either with the SMTP provider or your hosting environment's CA chain.
  
  It is recommended instead to **resolve the underlying issues with your hosting/SMTP service**, but if you want to connect to a server with a self signed certificate (for example) you can patch CiviCRM to bypass this verification.
  
  Change in packages/Net/SMTP.php
  
  line `$this->_socket_options = $socket_options;`
  
  to `$this->_socket_options = array('ssl' => array('verify_peer_name' => false));`
  
  Updated: I have updated the comment here since the summary in the [ref link](http://php.net/manual/en/migration56.openssl.php) has also been updated to include:
  
  > While not recommended in general, it is possible to disable peer certificate verification for a request by setting the verify\_peer context option to FALSE, and to disable peer name validation by setting the verify\_peer\_name context option to FALSE.
  
  The above works around the problem with SMTP failure however it is better to ensure the server is set up with valid SSL certificate and configurations.
  
  > **Comments:**
  > **username_1**: Are you sure all SMTP using TLS will fail, or just those using self-signed certificates which fail peer validation? Or hosting environments with outdated CA on the server.  
  > **username_7**: Works for me with SMTP via GMail. Thanks!  
  > **username_8**: I just ran into this as well. Should we be pushing to get this into core?  
  > **username_9**: Same here, ran into this issue with MailGun.  The above fixed it for me.  
  > **username_10**: With CiviCRM 4.7.15 and Joomla, I had to apply the single line patch to make this work with PHP 5.6, connecting to Sparkpost. Confused why this is still an outstanding issue after almost a year?  
  > **username_11**: Ditto here (CiviCRM 4.7.17/Joomla and PHP 5.6) - why is this not part of core? Been patching every silly CiviCRM upgrade ... sigh.  
  > **username_3**: "Since php has enabled peer verification by default from 5.6.x, all the SMTP connection via SSL and TLS will fail in CiviCRM." <-- Not true! If the certificates have been set up properly peer verification should pass.  
  > **username_1**: IMO this answer is bad advice (telling people to disable builtin security functionality to avoid hearing about issues in the hosting / SMTP environment). Since it has lots of upvotes, I've modified it to nudge people to a better solution, without wholesale rewriting the answer. I recommend people use Michael's solution instead.  
  > **username_12**: Can anyone elaborate on what I need to do to solve this problem?  I am running CiviCRM 4.7.18 on Drupal 7, newly installed Ubuntu 16.04 running php 5.6.x.  I am getting the error:  Failed to connect to tls://smtp.sparkpostmail.com:587 [SMTP: Failed to connect socket: (code: -1, response: )]  Yes, we are connecting to sparkpost.  I tried prepending tls:// to the host as well as without.  None of my other web apps - including drupal itself - have a problem with 5.6.  
  > **username_6**: We have tried to actively and passively solve this error with our mail provider, but we have always had the same answer saying that for its part everything was fine and that we should to deactivate this option by code.  
  
  ---
  
  ### Answer by username_2 on 2016-04-07. Score: 7
  
  I had to go this far...
  
  ```
  $this->_socket_options = array('ssl' => array('verify_peer'=>false,'verify_peer_name'=>false,'allow_self_signed'=>true));
  
  ```
  
  > **Comments:**
  > **username_3**: FWIW, if you are connecting to well known third party mail provider, then it's highly likely that they have their certificates set up properly and you shouldn't need to disable peer verification.  
  
  ---
  
  ### Answer by username_3 on 2017-03-22. Score: 6
  
  If you are connecting to well known third party mail provider, then it's highly likely that they have their certificates set up properly and ***you shouldn't need to disable peer verification***.
  
  Check two things:
  
  1. As it mentions on the *Settings - Outbound Mail* form, 'if the server uses SSL, add "ssl://" to the beginning of the server name'.
  2. Check what port you are using: "The most common SMTP port possibilities are 25, 465, and 587".
  
  And if the above does not resolve the issue, verify that the hosting environment's CA chain is up to date, since that will also trigger this problem.
  
  *Note: In the case of Mandrill, even though the <https://mandrillapp.com/settings> page specified port 587, ssl only worked on port 465 (as explainined in [this mandrill knowledge base article](https://mandrill.zendesk.com/hc/en-us/articles/205582177-Does-Mandrill-support-SSL-)).*
  
  > **Comments:**
  > **username_1**: 3. verify that the hosting environment's CA chain is up to date, since that will also trigger this problem  
  > **username_1**: PS. Yours is the correct answer, but the one recommending to disable peer verification has lots of votes   
  > **username_4**: Plus a zillion for not disabling peer verification! To speak directly to an example comment above our cert, ports, etc are set up properly and we have never had an issue connecting with Sparkpost using php 5.6.3.  
  > **username_3**: @username_1 and eli - might want to consider voting up the comments in the wrong answer as well so they are above the comment fold to help others.  
  > **username_5**: @username_4 how are you connecting to Sparkpost? I'm trying to figure out why it's not working for us. We're using Sparkpost, Let's Encrypt, and the PESC Sparkpost extension. The extension builders say it's a core Civi issue: https://github.com/proexchange/com.pesc.sparkpost/issues/22  
  > **username_4**: @username_5 we are connecting via the Sparkpost API using civiCRM 4.7.15 with the Cividesk sparkpost extension (rather than pesc). There is a post somewhere about the comparison. We are on PHP 5.6.30 (mistype earlier) and it seems to be working fine. Our SSL cert is with GoDaddy. We are using their premium EV cert to get our name in the green box :). We've got email and DKIM verified. Hope that is helpful.  
  
  ---
  
  ### Answer by username_6 on 2017-05-19. Score: 0
  
  Seems there is some work in progress to attach this on [CRM-18408
  SMTP connection via SSL and TLS in PHP 5.6](https://issues.civicrm.org/jira/browse/CRM-18408)
  
  
  ---
  
  