title: PHPMailer generates PHP Warning: stream_socket_enable_crypto(): Peer certificate did not match expected
body: <p>I am using PHPMailer on PHP 5.6, the increased security around certificated in PHP 5.6 is certainly fun.</p>
  
  <p>I am trying to send a test message to a domain hosted on dreamhost, the error that comes back from PHPMailer is: Could not connect to SMTP host.</p>
  
  <p>That error is not right though, I have logging enabled and here is what is actually going on.</p>
  
  <blockquote>
    <p>Connection: opening to mx1.sub4.homie.mail.dreamhost.com:25,
    timeout=30, options=array ( ) Connection: opened S: 220
    homiemail-mx32.g.dreamhost.com ESMTP</p>
    
    <p>C: EHLO s81a.ikbb.com</p>
    
    <p>S: 250-homiemail-mx32.g.dreamhost.com 250-PIPELINING 250-SIZE 40960000
    250-ETRN 250-STARTTLS 250-ENHANCEDSTATUSCODES 250 8BITMIME</p>
    
    <p>C: STARTTLS</p>
    
    <p>S: 220 2.0.0 Ready to start TLS</p>
    
    <p>C: QUIT</p>
    
    <p>S:  SMTP ERROR: QUIT command failed:  Connection: closed</p>
  </blockquote>
  
  <p>I could not understand why PHPMailer just gives up, issuing a QUIT command when it should start sending the message.  I got another clue from another log:</p>
  
  <p>PHP Warning:  stream_socket_enable_crypto(): Peer certificate CN=<code>*.mail.dreamhost.com' did not match expected CN=</code>mx1.sub4.homie.mail.dreamhost.com' in /home/ikbb/domains/dev.ikbb.com/public_html/includes/phpmailer/5.2.10/class.smtp.php</p>
  
  <p>If I use some custom options to prevent validation of the cert they are using I can get it to continue.  Here is what I have:</p>
  
  <pre><code>        $mail-&gt;SMTPOptions = array (
          'ssl' =&gt; array(
              'verify_peer'  =&gt; false,
              'verify_peer_name'  =&gt; false,
              'allow_self_signed' =&gt; true));
  </code></pre>
  
  <p>If I put the SMTPOptions in there and skip the peer verification, message goes OK - with no warning in PHP at all.</p>
  
  <p>How can I trap that error, so I know there is an issue but still send the message?</p>