WINDOWS 10 PHPMailer SMTP connect() failed
Posted by: cjsdfw (70.45.179.---)
Date: March 31, 2016 11:49AM

PHPMailer fails to connect:
Mailer error: SMTP connect() failed. [github.com]

I have followed the suggested troubleshooting hits in the refered link:
i) DNS resolution working (verified)
ii) Disabling firewall does not resolve issue
iii) Opensll loaded (per PhpInfo output)
iv) I used a test script to test and request SMTPDebug=4. Script and error messages are posted below. The exact same script tested on
Linux LAMP stack server and works fine but fails in Windows 10 WampServer installation.

Following post suggests php_smtp.dll is needed, I don't know enough to know:
[thewwwbloggers.blogspot.com]

I appreciate any help.

1 - Windows 10 64 Bits
2 - Version WampServer: wampserver3_x64
3 - Apache Version: apache2.4.17
4 - PHP Version: php5.6.16
5 - MySQL Version: mysql5.7.9
6 - WampServer icon: Green

7 - c:\Windows\System32\drivers\etc\hosts
127.0.0.1 localhost
::1 localhost

8 - Localhost access OK
9 - phpMyAdmin access OK

11 - Antivirus Avast
Firewall Windows integrated firewall

12 - Wampserver Path C:\wamp64

10 - Error Message Relates

Test Script:

<?php
require("PHPMailerAutoload.php"winking smiley ; // path to the PHPMailerAutoload.php file.

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = "smtp";
$mail->Host = "smtp.gmail.com";
$mail->Port = "587"; // 8025, 587 and 25 can also be used. Use Port 465 for SSL.
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'tls';
$mail->Username = "cjsdfw@gmail.com";
$mail->Password = "********";
$mail->SMTPDebug = 4; // enables SMTP debug information (for testing)

$mail->From = "cjsdfw@gmail.com";
$mail->FromName = "Carlos";
$mail->AddAddress("cjsdfw@HOTMAIL.COM", "Carlos"winking smiley ;
$mail->AddReplyTo("cjsdfw@gmail.com", "Carlos"winking smiley ;

$mail->Subject = "Hi";
$mail->Body = "Hi! How are you?";
$mail->WordWrap = 50;

if(!$mail->Send()) {
echo '<br>'.'Message was not sent.'.'<br>';
echo 'Mailer error: ' . $mail->ErrorInfo;
exit;
} else {
echo 'Message has been sent.';
}
?>

Error Message:

2016-03-31 09:02:56 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( )
2016-03-31 09:02:56 Connection: opened 2016-03-31 09:02:56 SMTP -> get_lines(): $data is ""
2016-03-31 09:02:56 SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP 70sm1588168ual.12 - gsmtp "
2016-03-31 09:02:56 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP 70sm1588168ual.12 - gsmtp 2016-03-31 09:02:56 CLIENT -> SERVER: EHLO joomla
2016-03-31 09:02:56 SMTP -> get_lines(): $data is "" 2016-03-31 09:02:56 SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [External-IP-Address-Masked] "
2016-03-31 09:02:56 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [External-IP-Address-Masked] "
2016-03-31 09:02:56 SMTP -> get_lines(): $str is "250-SIZE 35882577 " 2016-03-31 09:02:56 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [External-IP-Address-Masked] 250-SIZE 35882577 "
2016-03-31 09:02:56 SMTP -> get_lines(): $str is "250-8BITMIME "
2016-03-31 09:02:56 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [External-IP-Address-Masked] 250-SIZE 35882577 250-8BITMIME "
2016-03-31 09:02:56 SMTP -> get_lines(): $str is "250-STARTTLS " 2016-03-31 09:02:56 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [External-IP-Address-Masked] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS "
2016-03-31 09:02:56 SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES "
2016-03-31 09:02:56 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [External-IP-Address-Masked] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES "
2016-03-31 09:02:56 SMTP -> get_lines(): $str is "250-PIPELINING "
2016-03-31 09:02:56 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [External-IP-Address-Masked] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING "
2016-03-31 09:02:56 SMTP -> get_lines(): $str is "250 SMTPUTF8 "
2016-03-31 09:02:56 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [External-IP-Address-Masked] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250 SMTPUTF8
2016-03-31 09:02:56 CLIENT -> SERVER: STARTTLS
2016-03-31 09:02:56 SMTP -> get_lines(): $data is ""
2016-03-31 09:02:56 SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS "
2016-03-31 09:02:56 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2016-03-31 09:02:56 SMTP Error: Could not connect to SMTP host.
2016-03-31 09:02:56 CLIENT -> SERVER: QUIT
2016-03-31 09:02:56 SMTP -> get_lines(): $data is ""
2016-03-31 09:02:56 SMTP -> get_lines(): $str is ""
2016-03-31 09:02:56 SERVER -> CLIENT:
2016-03-31 09:02:56 SMTP ERROR: QUIT command failed:
2016-03-31 09:02:56 Connection: closed
2016-03-31 09:02:56 SMTP connect() failed. [github.com]

Options: ReplyQuote
Re: WINDOWS 10 PHPMailer SMTP connect() failed
Posted by: RiggsFolly (Moderator)
Date: March 31, 2016 12:41PM

Hi,

Looking at the phpMailer documentation here and the phpMailer Troubleshooting documentation here

It seems likely that you have not activated the php_openssl extension.

If you use this

$mail->SMTPSecure = 'tls';
you are asking for a secure connection and therefore need PHP to be able to talk securely

To activate php_openssl you use the wampmanager menus like this

left click wampmanager -> PHP -> PHP Extensions -> php_openssl

If this line in the menu does ot have a TICK beside it, click the php_openssl menu and wampmanager wil activate the extension and restart Apache and you should be good to go.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: WINDOWS 10 PHPMailer SMTP connect() failed
Posted by: cjsdfw (24.41.131.---)
Date: March 31, 2016 04:58PM

Hi RiggsFolly and thanks for replying so fast!

php_openssl is already active (green check mark visible and verified through phpinfo)

I have tried this in two different computers configured with same versions of Windows and Wamp 3 and connected to two different ISP's with same results: connect failed.

any other ideas?

Can you confirm that php_smtp.dll is indeed not needed?

Thanks,
Carlos

Options: ReplyQuote
Re: WINDOWS 10 PHPMailer SMTP connect() failed
Posted by: RiggsFolly (Moderator)
Date: March 31, 2016 05:36PM

Carlos,

Turn it on anyway, see if it helps. It wont do anything other than use a bit of memory if it is not required and if thats the case you can turn it off again the sae way you tiurn them on.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote
Re: WINDOWS 10 PHPMailer SMTP connect() failed
Posted by: Otomatic (Moderator)
Date: March 31, 2016 06:07PM

Hi,

Here how I use PHPmailer

require_once('inc/class.phpmailer.php');
require_once('inc/class.smtp.php');
$subject = "Content of the subject";
$message = "Content of the message itself";

$mail = new PHPMailer();
$mail->SetLanguage('en');
$mail->IsSMTP();
$mail->IsHTML      = false;
$mail->SMTPDebug   = false;
$mail->SMTPAuth    = true;

//Parameters for the SMTP server
$mail->Host        = "smtp_host_name"; // To be modified for example 'mail.gandi.net'
// Using an authenticated SMTP (SMTPAuth = true) and according
// to the ISP (Internet Service Provider) the port to use
// and the associated protocol may be different.
// This is the ISP which provides the sending SMTP settings.
$mail->Port        = 25; //25 or 587 or '465 SSL' or '995 TLS'
//$mail->SMTPSecure = "tls"; // tls or ssl Not always necessary
$mail->Username    = "foo@mysite.net"; // To be modified
$mail->Password    = "my_password"; // To be modified

$mail->From        = "me@mysite.net";// To be modified
$mail->FromName    = "Otomatic"; // To be modified
//Administrator is also recipient
$mail->AddAddress("admin@mysite.net", "Site Administrator"winking smiley; // To be modified

//Features of the message
$mail->CharSet     = "utf-8";
$mail->Subject     = $subject;
$mail->Body        = $message;

if(!$mail->Send())
 echo "Mail invoice error": ".$mail->ErrorInfo;

$mail->SmtpClose();
php_smtp.dll is not needed.

---------------------------------------------------------------
Documentation Apache - Documentation PHP - Documentation MySQL - Wampserver install files & addons

Options: ReplyQuote
Re: WINDOWS 10 PHPMailer SMTP connect() failed
Posted by: cjsdfw (24.41.131.---)
Date: March 31, 2016 08:50PM

Otomatic and RiggsFolly: Thanks both for replying:

I tried Otomatic's script and I get the same results as from my script (same error).

Here is PHP error log which seems to point the problem at an OpenSSL certificate needed? Like I said earlier I am not that knowledgable about the topic but maybe it tells you more.


[31-Mar-2016 14:05:46 America/Puerto_Rico] PHP Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086confused smileySL routinesconfused smileySL3_GET_SERVER_CERTIFICATE:certificate verify failed in C:\wamp64\www\joomla\mailer\class.smtp.php on line 344

[31-Mar-2016 14:05:46 America/Puerto_Rico] PHP Stack trace:

[31-Mar-2016 14:05:46 America/Puerto_Rico] PHP 1. {main}() C:\wamp64\www\joomla\mailer\test.php:0

[31-Mar-2016 14:05:46 America/Puerto_Rico] PHP 2. PHPMailer->send() C:\wamp64\www\joomla\mailer\test.php:24

[31-Mar-2016 14:05:46 America/Puerto_Rico] PHP 3. PHPMailer->postSend() C:\wamp64\www\joomla\mailer\class.phpmailer.php:1176

[31-Mar-2016 14:05:46 America/Puerto_Rico] PHP 4. PHPMailer->smtpSend() C:\wamp64\www\joomla\mailer\class.phpmailer.php:1296

[31-Mar-2016 14:05:46 America/Puerto_Rico] PHP 5. PHPMailer->smtpConnect() C:\wamp64\www\joomla\mailer\class.phpmailer.php:1459

[31-Mar-2016 14:05:46 America/Puerto_Rico] PHP 6. SMTP->startTLS() C:\wamp64\www\joomla\mailer\class.phpmailer.php:1591

[31-Mar-2016 14:05:46 America/Puerto_Rico] PHP 7. stream_socket_enable_crypto() C:\wamp64\www\joomla\mailer\class.smtp.php:344

Options: ReplyQuote
Re: WINDOWS 10 PHPMailer SMTP connect() failed
Posted by: RiggsFolly (Moderator)
Date: March 31, 2016 08:55PM

I think you should try asking this question on the phpMailer site. Or the Joomla site.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-



Edited 1 time(s). Last edit at 03/31/2016 08:55PM by RiggsFolly.

Options: ReplyQuote
Re: WINDOWS 10 PHPMailer SMTP connect() failed
Posted by: cjsdfw (70.45.179.---)
Date: April 01, 2016 12:14AM

Ok, I will ask in PHPMailer forum, Joomla is not involved as I am doing this with the PHPMailer class alone. I installed PHPMailer to isolate Joomla from the equation.

Thanks so much for all your help. Amazing support indeed!

Carlos

Options: ReplyQuote
Re: WINDOWS 10 PHPMailer SMTP connect() failed
Posted by: cjsdfw (70.45.179.---)
Date: April 01, 2016 12:31AM

Hi guys, for completeness and info to others experiencing a similar problem I want to post what I just found out in the PHPMailer site as it did resolve the issue for me. I guess in my case this is good enough as this is NOT a production server but rather a development one. Thanks again for all the help, again amazing support response in this site!

From: [github.com]


In a change from earlier versions, PHP 5.6 verifies certificates on SSL connections. If the SSL config of the server you are connecting to is not correct, you will get an error like this:

Warning: stream_socket_enable_crypto(): SSL operation failed with code 1.
OpenSSL Error messages: error:14090086confused smileySL routinesconfused smileySL3_GET_SERVER_CERTIFICATE:certificate verify failed

The correct fix for this is to replace the invalid, misconfigured or self-signed certificate with a good one. Failing that, you can allow insecure connections via the SMTPOptions property introduced in PHPMailer 5.2.10 (it's possible to do this by subclassing the SMTP class in earlier versions), though this is not recommended:

$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);

Options: ReplyQuote
Re: WINDOWS 10 PHPMailer SMTP connect() failed
Posted by: RiggsFolly (Moderator)
Date: April 01, 2016 09:58AM

Thanks for the update.

---------------------------------------------------------------------------------------------
(Windows 10 Pro 64bit) (Wampserver 3.3.4 64bit) Aestan Tray Menu 3.2.5.4
<Apache versions MULTIPE> <PHP versions MULTIPLE> <MySQL Versions MULTIPLE>
<MariaDB versions MULTIPLE> <phpMyAdmin versions MULTIPLE> <MySQL Workbench 8.0.23>

Read The Manuals Apache -- MySQL -- PHP -- phpMyAdmin
Get your Apache/MySQL/mariaDB/PHP ADDONs here from the WAMPServer alternate Repo
-X-X-X- Backup your databases regularly Here is How dont regret it later! Yes even when developing -X-X-X-

Options: ReplyQuote


Sorry, only registered users may post in this forum.