phpmailer connection refused .. line 254

My mail server is accepting mail() connections. However, I'm changing to phpmailer and got an error message that I don't understand.
Here's the phpmailer code that I'm using:
<?php
            $subject = "Registration Confirmation";

            // The non-HTML text
            $alt_body = "\r\n** CONFIDENTIAL **\r\n\r\n";
            $alt_body .= "Thank you for registering.\r\n\r\n";

            // HTML text
            $body = "** CONFIDENTIAL **<br><br>";
            $body .= "Thank you for registering.<br><br>";

            $mail = new PHPMailer;

            $mail->SMTPDebug = 3;                               // Enable verbose debug output   ####################### CHANGE TO 0 FOR PRODUCTION ##############################

            $mail->isSMTP();                                      // Set mailer to use SMTP
            $mail->Host = 'smtp.example.com';  // Specify main and backup SMTP servers
            $mail->SMTPAuth = true;                               // Enable SMTP authentication
            $mail->Username = "support@example.com";                 // SMTP username
            $mail->Password = "password";                           // SMTP password
            $mail->SMTPSecure = 'none';                            // Enable TLS encryption, `ssl` also accepted
            $mail->Port = 587;                                    // TCP port to connect to

            $mail->From = 'support@example.com';
            $mail->FromName = "Support";
            $mail->addAddress("name@gmail.com");     // Add a recipient
            $mail->addReplyTo('support@example.com', 'Support');
            $mail->WordWrap = 50;
            $mail->isHTML(true);                                  // Set email format to HTML

            $mail->Subject = $subject;
            $mail->Body    = $body;
            $mail->AltBody = $alt_body;

            if(!$mail->send()) {
                echo 'Message could not be sent.';
                echo 'Mailer Error: ' . $mail->ErrorInfo;
            } else {
                echo 'Message has been sent';
            }
?>

Open in new window


And the error message:
2015-04-10 18:46:57 Connection: opening to smtp.example.com:587, t=300, opt=array ( )

Error '2'
occurred in script '/folders/includes/class.smtp.php' on line 254:
stream_socket_client(): unable to connect to smtp.example.com:587 (Connection refused)
with 'Array'
Date/Time: 10-4-2015 14:46:57

2015-04-10 18:46:57 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-04-10 18:46:57 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.temp exit

Open in new window


And the chunk of class.smtp.php code that's pointed at:
<?php
// In class.smtp.php ..
        if ($streamok) {
            $socket_context = stream_context_create($options);
            //Suppress errors; connection failures are handled at a higher level
            $this->smtp_conn = @stream_socket_client(
                $host . ":" . $port,
                $errno,
                $errstr,
                $timeout,
                STREAM_CLIENT_CONNECT,
                $socket_context
            );                                     // <<<<<<<<<<<<< LINE 254 IN class.smtp.php <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Open in new window


I cannot find where STREAM_CLIENT_CONNECT is defined in either class.smtp.php or class.phpmailer.php . Could that be the issue?
Ideas?
Torquil BeavisBusinessAsked:
Who is Participating?
 
Marcus BointonConnect With a Mentor Commented:
Yes, and that is covered in the PHPMailer docs https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
0
 
Marco GasiFreelancerCommented:
You have to ask your provider: phpmailer works if the server support smtp mail traffic (mail() function doesn't use SMTP). o the problem is some server configuration and probably they will can give you the solution.
0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
STREAM_CLIENT_CONNECT is probably a PHP constant that isn't normally visible to you.  I think what you have been running into is that your host has blocked the ports that are needed to connect to external mail servers.  That is exactly what I described for Godaddy where mail() works on port 25 and all of the other ports like 465 and 587 are blocked to prevent you from using them.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Torquil BeavisBusinessAuthor Commented:
I just talked to the web host 2nd level support, and they said that class.smtp.php is not getting the username and pw that is in my calling script.   class.phpmailer.php and class.smtp.php are both in the includes folder and correctly directed. Support said there may be something that needs adjusted in class.smtp.php that is causing the line 254 error. They do not believe it has anything to do with the php constant STREAM_CLIENT_CONNECT not being available.
Also, they said they have ports 25 and 587 open. 587 is the smtp port that they told me to use when testing smtp in another post.
0
 
Dave BaldwinFixer of ProblemsCommented:
What version of PHPMailer do you have?  I can not find STREAM_CLIENT_CONNECT in any file in PHPMailer in the 4 versions that I have.  I also can not find $this->smtp_conn = @stream_socket_client in any of them.
0
 
Torquil BeavisBusinessAuthor Commented:
class.phpmailer.php:
* PHPMailer - PHP email creation and transport class.
 * PHP Version 5
 * @package PHPMailer
 * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
 * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
 * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
 * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
 * @author Brent R. Matzelle (original founder)
 * @copyright 2012 - 2014 Marcus Bointon
 * @copyright 2010 - 2012 Jim Jagielski
 * @copyright 2004 - 2009 Andy Prevost
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 * @note This program is distributed in the hope that it will be useful - WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 */
/**
 * PHPMailer - PHP email creation and transport class.
 * @package PHPMailer
 * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
 * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
 * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
 * @author Brent R. Matzelle (original founder)
 */
class PHPMailer
{
    /**
     * The PHPMailer Version number.
     * @type string
     */
    public $Version = '5.2.9';

Open in new window


class.smtp.php:
  
 * PHPMailer RFC821 SMTP email transport class.
 * PHP Version 5
 * @package PHPMailer
 * @link https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project
 * @author Marcus Bointon (Synchro/coolbru) <phpmailer@synchromedia.co.uk>
 * @author Jim Jagielski (jimjag) <jimjag@gmail.com>
 * @author Andy Prevost (codeworxtech) <codeworxtech@users.sourceforge.net>
 * @author Brent R. Matzelle (original founder)
 * @copyright 2014 Marcus Bointon
 * @copyright 2010 - 2012 Jim Jagielski
 * @copyright 2004 - 2009 Andy Prevost
 * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
 * @note This program is distributed in the hope that it will be useful - WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 */
/**
 * PHPMailer RFC821 SMTP email transport class.
 * Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server.
 * @package PHPMailer
 * @author Chris Ryan
 * @author Marcus Bointon <phpmailer@synchromedia.co.uk>
 */
class SMTP
{
    /**
     * The PHPMailer SMTP version number.
     * @type string
     */
    const VERSION = '5.2.9';

Open in new window


The server uses PHP 5.3.3-7
0
 
Torquil BeavisBusinessAuthor Commented:
Does this make sense to you? Could this be the issue, perhaps?
From: https://github.com/PHPMailer/PHPMailer/blob/master/changelog.md

Version 5.2.9 (Sept 25th 2014)
Important: The autoloader is no longer autoloaded by the PHPMailer class

Open in new window

0
 
Torquil BeavisBusinessAuthor Commented:
And ..
I don't use Drupal, but this seems like what I'm experiencing ..
From: https://www.drupal.org/node/2381475

Here are the release note from PHPMailer library 5.2.9 (latest version):

The autoloader is no longer autoloaded automatically, and the PHPMailer class does not require the SMTP class explicitly, so you must either load the autoloader yourself (as all the docs and examples have done for the last year), or load the SMTP class yourself. This fixes the inability to substitute your own SMTP subclass, and also improves interoperability with other autoloaders.

It means that the SMTP class is not loaded anymore, which make the module crash when trying to send an email.

Open in new window

0
 
Torquil BeavisBusinessAuthor Commented:
I got them from ..
https://github.com/Synchro/PHPMailer/blob/master/class.smtp.php  and  /class.phpmailer.php
0
 
Dave BaldwinFixer of ProblemsCommented:
I just downloaded the ZIP for PHPMailer v5.2.9 with all of the files and modified their 'gmail.phps' to 'gmail.php' with my own info from the previous version.  Turns out that Gmail is rejecting both versions now.
0
 
Torquil BeavisBusinessAuthor Commented:
Is there someone out there who has installed PHPMailer 5.2.9 successfully with or without autoload? I'm not finding clear instructions as to how to implement PHPMailer - it seems I don't talk github!
0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
It installed just fine and I can use it to send thru an account on Godaddy to an account on another host.  It's just that Gmail will not accept it.  Matter of fact, they sent me an email on another account telling me that someone had tried to access my Gmail account and that they had the password.

Those two files you listed above are only a small part of PHPMailer 5.2.9.  I downloaded the ZIP from the main GitHub page for PHPMailer and unzipped it into it's own directory on my server.  Then I edited 'smtp.phps' (after saving it to 'smtp,php') to put in my own email account info.  That worked fine.  'gmail.php' also worked but Gmail rejected the email.

I have PHPMailer versions 5.1, 5.2.1, 5.2.4, and now 5.2.9.  They all work except where they are blocked by other servers.
0
 
Torquil BeavisBusinessAuthor Commented:
Great!
Dave, I'd appreciate you taking me through the steps. I have unzipped and put class.phpmailer.php and class.smtp.php into my includes directory. Should they not be named as 'class.' before phpmailer.php and smtp.php ? And do you use autoloader somehow, or just 'require' the two files without autoloader?
0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
I wouldn't do that, that's not enough.  For test purposes, I would create a PHPMailer directory and unzip ALL of the files into it using the directory structure in the ZIP file.  Then edit file 'smtp.phps' in the examples directory and edit it to put in your credentials and an address to send the email to that you can check.

This is what is in my directories.  I changed the '*.phps' files to '*.php' because I'm not set up to run them as '*.phps'.
PHPMailer 5.2.9PHPMailer 5.2.9 Examples
0
 
Marcus BointonConnect With a Mentor Commented:
STREAM_CLIENT_CONNECT Is a PHP built-in constant.

There's a lot of confusion in the above posts. What you need to install and how to load PHPMailer is quite straightforward and covered in the readme.

You should use the autoloader.

PHPMailer lives at https://github.com/PHPMailer/PHPMailer. The Synchro repo is my personal fork, so don't use that, and yes I know that some pages link there, but they are not under my control.

The examples are deliberately saved with a .phps extension as otherwise they could represent a security hole or spam gateway. PHP by default renders .phps files as syntax-highlighted source code.
0
 
Dave BaldwinConnect With a Mentor Fixer of ProblemsCommented:
I always download the ZIP and unzip it as I have shown above.  For what it's worth, Gmail doesn't like you trying to access it that way anymore.  An email I got from them says I can log on and turn off some advanced security if I wanted to.
You can switch to an app made by Google such as Gmail to access your account (recommended) or change your settings at https://www.google.com/settings/security/lesssecureapps so that your account is no longer protected by modern security standards.
0
 
Torquil BeavisBusinessAuthor Commented:
Thank you both. I erased all files, and zipped from PHPMailer, placing those unzipped files in a PHPMailer directory which is in the includes folder.

 Then I used the readme example script and adjusted the values to test the script. In the following script, 'example' is in place of the actual name, the username and password are correctly applied, and addresses are also correctly applied.

<?php
// phpmailer test script

require 'includes/PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

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

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.example.com'; // sets the SMTP server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'example@example.com';                 // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->From = 'support@example.com';
$mail->FromName = 'Support';
$mail->addAddress('user@gmail.com', 'User');     // Add a recipient
$mail->addAddress('myself@gmail.com');               // Name is optional
$mail->addReplyTo('support@example.com', 'Support');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message has been sent';
}
?>

Open in new window


Here is the output (with 'example' replacing the actual name):

2015-04-12 17:11:13 Connection: opening to smtp.example.com:587, t=300, opt=array ( ) 2015-04-12 17:11:13 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-04-12 17:11:13 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.  

Open in new window


So, I went through the checks in 'troubleshooting' (except DNS since I'm sure that's correct), with the ping successful, and the telnet successful. Then I ran the smtp_check.php (copied from smtp_check.phps which did not run):

<?php
/**
 * This uses the SMTP class alone to check that a connection can be made to an SMTP server,
 * authenticate, then disconnect
 */

//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/GMT-7');      // Vancouver, BC

require '../PHPMailerAutoload.php';

//Create a new SMTP instance
$smtp = new SMTP;

//Enable connection-level debug output
$smtp->do_debug = SMTP::DEBUG_CONNECTION;

try {
//Connect to an SMTP server
    if ($smtp->connect('smtp.example.com', 587)) {                          // was 25 timed out     587 no delay    Both: 'connect failed'
        //Say hello
        if ($smtp->hello('smtp.example.com')) { //Put your host name in here
            //Authenticate
            if ($smtp->authenticate('username', 'password')) {
                echo "Connected ok!";
            } else {
                throw new Exception('Authentication failed: ' . $smtp->getLastReply());
            }
        } else {
            throw new Exception('HELO failed: '. $smtp->getLastReply());
        }
    } else {
        throw new Exception('Connect failed');
    }
} catch (Exception $e) {
    echo 'SMTP error: '. $e->getMessage(), "\n";
}
//Whatever happened, close the connection.
$smtp->quit(true);
?>

Open in new window


Since the web host confirmed 587 as the mail port and my server is located in Vancouver, BC, I applied those changes (including date_default_timezone_set('Etc/GMT-7');) over and above the host, username and pw as before.
The output:
2015-04-12 16:50:09 Connection: opening to smtp.example.com:587, t=30, opt=array ( ) 2015-04-12 16:50:09 SMTP ERROR: Failed to connect to server: Connection refused (111) SMTP error: Connect failed  

Open in new window


Firewall redirection is not likely since I use port 587 and the error was 'connect failed' rather than 'authentication failed'.
Is this the gmail issue?

Any ideas what I should try next?
0
 
Marcus BointonConnect With a Mentor Commented:
It would only be the gmail issue if you're connecting to gmail.

You say that telnet worked - from the same server, as the same user?

Does SMTPDebug = 4 tell you anything new?
0
 
Dave BaldwinFixer of ProblemsCommented:
"Connection refused" is the important part of the message.  Everything about that message shows that PHPMailer is working but I believe "Connection refused" is from the remote server.  Do you have a different remote server that you can connect to for a test?
0
 
Torquil BeavisBusinessAuthor Commented:
"You say that telnet worked - from the same server, as the same user?" -> Yes.
"Does SMTPDebug = 4 tell you anything new?" -> Only what's in the above message.
"Do you have a different remote (mail) server" -> No.

I also used the mail server IP address but with the same results.

Is there any way of getting more detailed data that could point to the error/issue?
0
 
Marcus BointonConnect With a Mentor Commented:
It's very strange that telnet works but PHP does not - they should be indistinguishable as far as the remote server is concerned. Can you try the same connection test but to smtp.gmail.com? The login doesn't need to work, but telnet and connect should.
0
 
Torquil BeavisBusinessAuthor Commented:
Connect:
2015-04-12 21:22:47 Connection: opening to smtp.gmail.com:587, t=300, opt=array ( ) 2015-04-12 21:22:47 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-04-12 21:22:47 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

Open in new window

2015-04-12 21:28:54 Connection: opening to smtp.gmail.com:465, t=300, opt=array ( ) 2015-04-12 21:28:54 SMTP ERROR: Failed to connect to server: Connection refused (111) 2015-04-12 21:28:54 SMTP connect() failed. Message could not be sent.Mailer Error: SMTP connect() failed.

Open in new window

Telnet:
Successful: "220 mx.google.com ESMTP ..digits.. - gsmtp"
0
 
Marcus BointonConnect With a Mentor Commented:
That difference suggests a PHP config issue. Are fopen wrappers enabled? Openssl extension enabled?
0
 
Torquil BeavisBusinessAuthor Commented:
From phpinfo.php:

openssl:
OpenSSL support 	enabled
OpenSSL Library Version 	OpenSSL 1.0.1e 11 Feb 2013
OpenSSL Header Version 	OpenSSL 1.0.1e 11 Feb 2013 

Open in new window


From php.ini:

;;;;;;;;;;;;;;;;;;
; Fopen wrappers ;
;;;;;;;;;;;;;;;;;;

; Whether to allow the treatment of URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-fopen
allow_url_fopen = On

; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
; http://php.net/allow-url-include
allow_url_include = On

; Define the anonymous ftp password (your email address). PHP's default setting
; for this is empty.
; http://php.net/from
;from="john@doe.com"

; Define the User-Agent string. PHP's default setting for this is empty.
; http://php.net/user-agent
;user_agent="PHP"

; Default timeout for socket based streams (seconds)
; http://php.net/default-socket-timeout
default_socket_timeout = 60

; If your scripts have to deal with files from Macintosh systems,
; or you are running on a Mac and need to deal with files from
; unix or win32 systems, setting this flag will cause PHP to
; automatically detect the EOL character in those files so that
; fgets() and file() will work regardless of the source of the file.
; http://php.net/auto-detect-line-endings
;auto_detect_line_endings = Off

Open in new window


Can you tell from these whether fopen wrappers are enabled and if Openssl extension is enabled?
0
 
Marcus BointonConnect With a Mentor Commented:
Try this little script. It checks whether PHP can connect to gmail SMTP (and it's simple to point it elsewhere):

<?php
$fp = fsockopen('tcp://smtp.gmail.com', 587, $errno, $errstr, 10);
echo fgets($fp, 128);
var_dump($fp, $errno, $errstr);
fclose($fp);

Open in new window


If it works you'll see a line like '220 mx.google.com ESMTP fa8sm10140669wib.14 - gsmtp'. Try substituting your own server, port etc.
0
 
Dave BaldwinFixer of ProblemsCommented:
Squinky,

That works on this computer, my main hosting, my Godaddy Windows hosting, but not on my Godaddy Linux hosting.  I get several messages saying that 'connection refused'.
0
 
Marcus BointonCommented:
OK, that will be godaddy blocking your outbound connection. Either ask them to remove it or find a better ISP!
0
 
Dave BaldwinFixer of ProblemsCommented:
My Godaddy accounts are just for testing because I have so many clients on Godaddy.  My own site is on Hurricane Electric and I have had very problems with them.  Although they have added some restrictions because of people's bad behavior over the years.
0
 
Torquil BeavisBusinessAuthor Commented:
I tried it using gmail on 587 and 465 and example on 587 and 465. Also tried ssl. All gave this error:
Warning: fsockopen(): unable to connect to tcp://smtp.example.com:587 (Connection refused) in /folders/squinky-connect-test.php on line 4 Warning: fgets() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 5 bool(false) int(111) string(18) "Connection refused" Warning: fclose() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 7 

Open in new window

0
 
Torquil BeavisBusinessAuthor Commented:
I use shared hosting at NetNation.ca (parent is Hostway.com). I've used NetNation.ca now for 16 years without major issues. Have you heard of these companies?
0
 
Marcus BointonConnect With a Mentor Commented:
Well, connections to example.com will always fail anyway, but this does suggest that your problem is down to some blockage caused by php.ini settings. It seems it's not a firewall thing because telnet works to the same targets. You can check the state of various applicable settings like this:

var_dump(ini_get('disable_functions'));
var_dump(ini_get('safe_mode')); //No longer in PHP as of 5.4
var_dump(ini_get('allow_url_fopen'));
var_dump(stream_get_transports());

Open in new window

Any of those may give some clue as to what's blocking it. It's common to block things like these on shared hosting.
0
 
Torquil BeavisBusinessAuthor Commented:
My bad .. I forgot to mention that example is the sanitized name ;)
I added:
var_dump(ini_get('disable_functions'));
so that the script was:
<?php
$fp = fsockopen('tcp://smtp.gmail.com', 587, $errno, $errstr, 10);            
echo fgets($fp, 128);
var_dump(ini_get('disable_functions'));
//var_dump(ini_get('safe_mode')); //No longer in PHP as of 5.4
//var_dump(ini_get('allow_url_fopen'));
//var_dump(stream_get_transports());
var_dump($fp, $errno, $errstr);
fclose($fp);
?>

Open in new window

and got:
Warning: fsockopen(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused) in /folders/squinky-connect-test.php on line 4 Warning: fgets() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 5 string(0) "" bool(false) int(111) string(18) "Connection refused" Warning: fclose() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 11 

Open in new window

Then I removed 'disable_functions' replacing with safe_mode, and got:
Warning: fsockopen(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused) in /folders/squinky-connect-test.php on line 4 Warning: fgets() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 5 string(0) "" bool(false) int(111) string(18) "Connection refused" Warning: fclose() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 11 

Open in new window

Similarly, allow_url_fopen:
Warning: fsockopen(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused) in /folders/squinky-connect-test.php on line 4 Warning: fgets() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 5 string(1) "1" bool(false) int(111) string(18) "Connection refused" Warning: fclose() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 11 

Open in new window

And stream_get_transports():
Warning: fsockopen(): unable to connect to tcp://smtp.gmail.com:587 (Connection refused) in /folders/squinky-connect-test.php on line 4 Warning: fgets() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 5 array(8) { [0]=> string(3) "tcp" [1]=> string(3) "udp" [2]=> string(4) "unix" [3]=> string(3) "udg" [4]=> string(3) "ssl" [5]=> string(5) "sslv3" [6]=> string(5) "sslv2" [7]=> string(3) "tls" } bool(false) int(111) string(18) "Connection refused" Warning: fclose() expects parameter 1 to be resource, boolean given in /folders/squinky-connect-test.php on line 11 

Open in new window


I repeated this for smtp.example.com, with identical results.

What does this tell you?
0
 
Torquil BeavisBusinessAuthor Commented:
Dave, you remember when I was having similar issues with mail(), solved the issue, then decided to use phpmailer due to potential mail() issues? Squinky, we had exhausted the tests and in frustration, I turned off the computer and router, then rebooted both. Magically, mail() worked. Of course I tried the same with phpmailer, but no cigar. Thought this may be useful data.
Can the router be failing/corrupting while mailing?
0
 
Marcus BointonCommented:
Just run those var_dumps without any other code - they don't make any difference to things working, they just tell us about your php config.

If you're using PHPMailer without SMTP, it will behave exactly like plain mail(). mail() can't send via SMTP so won't expose the limitations of your config when trying to do that.
0
 
Torquil BeavisBusinessAuthor Commented:
var_dump(ini_get('disable_functions'));
=> string(0) "" 

var_dump(ini_get('safe_mode')); //No longer in PHP as of 5.4
=> string(0) "" 

var_dump(ini_get('allow_url_fopen'));
=> string(1) "1" 

var_dump(stream_get_transports());
=> array(8) { [0]=> string(3) "tcp" [1]=> string(3) "udp" [2]=> string(4) "unix" [3]=> string(3) "udg" [4]=> string(3) "ssl" [5]=> string(5) "sslv3" [6]=> string(5) "sslv2" [7]=> string(3) "tls" } 

Open in new window


Do I need to change any php.ini settings?
0
 
Marcus BointonConnect With a Mentor Commented:
That's all quite mysterious. It's definitely your PHP config that's causing this, but I can't think what it could be. Perhaps open a ticket with your ISP?
0
 
Torquil BeavisBusinessAuthor Commented:
Web host ticket opened. I gave them the telnet line, saying it worked. They checked and agreed. Also, I gave them the smtp_check.php with my actual credentials, and they agreed it failed. So it's gone to 2nd level tech support. Normally takes 24-48 hours. I'll let you know how it plays out.
0
 
Torquil BeavisBusinessAuthor Commented:
It's working perfectly now.
Here's the dialogue with Support. I had hoped they would be more explicit since I thought you'd want to know the cause of this issue.

"Please let me know what prevented the script from working."

"There was a rule on the server, which prevented the use of the ports. Our Administrators had fixed that and it should not happen again."

"Which rule?"

"There is no particular specification of that rule. It was simply preventing the connection on the ports that the script was using. Our Administrators have fixed that."

Any idea what the "rule" could be? Could it be like Dave experienced with GoDaddy?
0
 
Marcus BointonConnect With a Mentor Commented:
Glad that worked out! Being a big ISP with shared hosting, they may have a kind of web app firewall that allows them finer-grained control than a network-level firewall, so they could block outbound ports on a per-app basis.
0
 
Torquil BeavisBusinessAuthor Commented:
Makes sense.
Thank you both for your assistance.
0
 
Torquil BeavisBusinessAuthor Commented:
Thank you both for your help. Really a great learning experience on top of getting the answer.
0
 
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.