tgun926
tgun926

Reputation: 1633

PHPMailer won't send with SSL but Outlook will

I'm having a problem trying to send an email on my local machine using PHPMailer and SSL (works fine without SSL), and I don't know where to start finding where the error is coming from.

Error:

2015-02-08 01:13:29 Connection: opening to ssl://mail.mydomain.com:465, t=300, opt=array ( ) 2015-02-08 01:13:29 SMTP ERROR: Failed to connect to server: (0) 2015-02-08 01:13:29 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

Here's my code I'm using to send:

$mail->SMTPDebug = 4;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'mail.mydomain.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = '[email protected]';                 // SMTP username
$mail->Password = 'xxxx';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to

$mail->From = '[email protected]';
$mail->FromName = 'Mailer';
$mail->addAddress('[email protected]');     // Add a recipient

This is what I have tried/observed:

I really don't know where to start looking, because I can send messages over ssl using a gmail account, but not with my own account, however I can if I use outlook.

Any ideas where I'm screwing up?

Edit:

nslookup results:

C:\Users\xxx>nslookup mail.xxxx.com
Server:  UnKnown
Address:  192.168.1.1

Non-authoritative answer:
Name:    xxxx.com
Address:  110.232.yyy.zzz (this is correct)
Aliases:  mail.xxxx.com

$ openssl s_client -starttls smtp -crlf -connect mail.xxxx.com:465
CONNECTED(00000003)

$ openssl s_client -crlf -connect mail.xxxx.com:465
CONNECTED(00000003)
depth=1 C = US, ST = Illinois, L = Chicago, O = "Trustwave Holdings, Inc.", CN = "Trustwave Organization Validation CA, Level 2", emailAddress = [email protected]
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
 0 s:/CN=*.zuver.net.au/O=Zuver Pty Ltd/L=Narre Warren/ST=VIC/C=AU
   i:/C=US/ST=Illinois/L=Chicago/O=Trustwave Holdings, Inc./CN=Trustwave Organization Validation CA, Level 2/[email protected]
 1 s:/C=US/ST=Illinois/L=Chicago/O=Trustwave Holdings, Inc./CN=Trustwave Organization Validation CA, Level 2/[email protected]
   i:/C=US/O=SecureTrust Corporation/CN=SecureTrust CA
---
Server certificate
-----BEGIN CERTIFICATE-----
MIIFLTCCBBWgAwIB...
-----END CERTIFICATE-----
subject=/CN=*.zuver.net.au/O=Zuver Pty Ltd/L=Narre Warren/ST=VIC/C=AU
issuer=/C=US/ST=Illinois/L=Chicago/O=Trustwave Holdings, Inc./CN=Trustwave Organization Validation CA, Level 2/[email protected]
---
No client certificate CA names sent
---
SSL handshake has read 3822 bytes and written 624 bytes
---
New, TLSv1/SSLv3, Cipher is DHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : DHE-RSA-AES256-GCM-SHA384
    Session-ID: 150CD8E826D73DD132572E...
    Session-ID-ctx:
    Master-Key: CCB6C3F...
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 200 (seconds)
    TLS session ticket:
    0000 - 57 3a ...

    Start Time: 1423438080
    Timeout   : 300 (sec)
    Verify return code: 20 (unable to get local issuer certificate)
---
220-zzz.zuver.net.au ESMTP Exim 4.84 #2 Mon, 09 Feb 2015 10:27:59 +1100
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.

Upvotes: 1

Views: 1982

Answers (1)

tgun926
tgun926

Reputation: 1633

After further testing, the problem happens only with PHP 5.6. It worked fine with PHP 5.5.

The reason is due to changes to OpenSSL in PHP 5.6, as outlined in this appendix, specifically:

Stream wrappers now verify peer certificates and host names by default when using SSL/TLS

As I was with a shared hosting plan, the SSL certificate was for server1.myhosting.com, and I was accessing my mail server by mail.mydomain.com. There is a mismatch because the SSL Certificate is issued for server1.myhosting.com

Changing my code to

$mail->Host = 'server1.myhosting.com';

fixed it for me.

N.B. I was advised to use server1.myhosting.com by my web hosting provider, so this might not work for you.

Upvotes: 1

Related Questions