Avatar of Torquil Beavis
Torquil Beavis
Flag for Canada asked on

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?
Email ProtocolsPHPEmail Servers

Avatar of undefined
Last Comment
Dave Baldwin

8/22/2022 - Mon
Marco Gasi

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.
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
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.
Dave Baldwin

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Torquil Beavis

ASKER
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
Torquil Beavis

ASKER
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

Torquil Beavis

ASKER
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

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
I got them from ..
https://github.com/Synchro/PHPMailer/blob/master/class.smtp.php  and  /class.phpmailer.php
Dave Baldwin

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.
Torquil Beavis

ASKER
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!
Your help has saved me hundreds of hours of internet surfing.
fblack61
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
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?
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Marcus Bointon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Dave Baldwin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Marcus Bointon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
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?
SOLUTION
Marcus Bointon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dave Baldwin

"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?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
"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?
SOLUTION
Marcus Bointon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
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"
SOLUTION
Marcus Bointon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
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?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
SOLUTION
Marcus Bointon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Dave Baldwin

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'.
Marcus Bointon

OK, that will be godaddy blocking your outbound connection. Either ask them to remove it or find a better ISP!
Dave Baldwin

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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
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

Torquil Beavis

ASKER
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?
SOLUTION
Marcus Bointon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
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?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Torquil Beavis

ASKER
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?
Marcus Bointon

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.
Torquil Beavis

ASKER
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?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Marcus Bointon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
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.
Torquil Beavis

ASKER
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?
SOLUTION
Marcus Bointon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Torquil Beavis

ASKER
Makes sense.
Thank you both for your assistance.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Torquil Beavis

ASKER
Thank you both for your help. Really a great learning experience on top of getting the answer.
Dave Baldwin

You're welcome, glad to help.