[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1172
  • Last Modified:

Warning fsockopen unable to connect

Gentleman:

I am attempting to use a "once functional" php mail script from my linux box on our new windows server.  Low and behold, and much to my surprise, it's no longer easy and operable :)

1. Windows 2000 Server
2. Exchange Server
3. PHP Version 4.3.1.0

I am getting kicked back an fsockopen warning telling me it cannot connect to our exchange mail server on port 25.  I've checked the php.ini file for the correct settings and all is in place.  The windows server sits on the DMZ and connects through a PIX firewall which my staff has confirmed is not blocking or preventing communication with the mail server.  

I did a test usng soupermail (cgi program) and it had no conflicts with sending mail.  Now I know what your thinking: "Why not just use Soupermail if its working" well... I like PHP and its easier than creating 14 config files and complementary templates for each form in my site.  

Any help is appreciated,

Thanks-
pmagony
0
pmagony
Asked:
pmagony
  • 9
  • 8
1 Solution
 
pmagonyAuthor Commented:
Anyone?
0
 
pmagonyAuthor Commented:
Here is the exact error that is being produced:

Warning: fsockopen() [function.fsockopen]: unable to connect to xxxx.xxxx.xxxx:25 (An established connection was aborted by the software in your host machine. ) in c:\PHP\includes\class.smtp.php on line 105
Message could not be sent.

Mailer Error: Language string failed to load: connect_host

As I had mentioned in my original post, the web server is in the DMZ and does have a firewall (PIX).  Exchange server requires authentication, which I am providing it with in the script.

Thanks again for your help-
0
 
Richard QuadlingSenior Software DeverloperCommented:
First of all, can you telnet to your exchange server's port 25?

I doubt you can.

Is your PHP.INI file using the correct server IP address. Make sure by telnetting THAT address on port 25.

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Richard QuadlingSenior Software DeverloperCommented:
Are you sending email to local users (i.e. users on the local exchange server) or are you using the exchange server as a relay?

If you are using it as a relay (i.e. you are sending email to people OUTSIDE of the local network), then take a look at my user notes on http://uk.php.net/manual/en/function.getmxrr.php#53182

By using this windows replacement for getmxrr() you can contact the users local SMTP handler, rather than using your own relay.

But, if you are double NATted through the firewall/DMZ, then you MAY have trouble and have to resort of feeding the local exchange server instead.

Here, I have ISA server and a WatchGuard firewall. Prior to the WatchGuard, I could use my own code. Now all my emails are relayed. Ho hum!

The primary issue for me was knowing if the recipients server had accepted the email. I now no longer no that and have to have people tell me that they didn't get that days report.

0
 
fncuisCommented:
RQ,

Thanks for the response.  I am unable to telnet to the exchange server.  It kicks back:  could not open a connection to host  on port 25
Further, if I do not specify the 'port' it tells me: could not open a connection to host on port 23 (telnet port I imagine...)  I tried telnet'ing the pdc server and that also failed.

I am sending emails to local users (form results from the website) and an auto-response to the (remote) user that submitted the form.

I'll take a look at your post for getmxrr(), it looks promising... however, I don't want to let go of this branch just yet.  I really want to <u>understand</u> why I am unable to send mail from our webserver.  

Maybe you can answer this question which is puzzling me... why am I able to send form results using soupermail through the CGI and not with a simple PHP script?

Thank you once again-
0
 
Richard QuadlingSenior Software DeverloperCommented:
Your mailserver may NOT have SMTP enabled.

Don't forget, then Outlook is a CDO client. It does not use SMTP to talk to the exchange server.

You have to enable SMTP for Exchange.

If you need further help with Exchange, you would be best to go and talk to the exchange people here. At least they will be able to tell you where you can find out if SMTP is enabled/filtered/restricted/etc.

I could look at our server, but I wouldn't want to guarantee that I know what I'm talking about!!! Not with Exchange anyway.

With PHP, no problem!!!!!


Try this at a command prompt ...

ipconfig /all

to find the default gateway IP address

then ...

nslookup -q=mx experts-exchange.com xxxxxxx

where xxxxx is the IP address of your default gateway.


I get back ...

Server:  master.bandvulc
Address:  10.0.0.7

Non-authoritative answer:
experts-exchange.com    MX preference = 1, mail exchanger = mail.experts-exchange.com

mail.experts-exchange.com       internet address = 64.156.132.251

The server mail.experts-exchange.com is THE SMTP server dealing with email for experts-exchange.com

Try this for bt.com or your own domain.

Then you see the MX preference. THis all links together.
0
 
pmagonyAuthor Commented:
How can I verify the exchange server is SMTP enabled???

0
 
pmagonyAuthor Commented:
My NetAdmin just verified it is enabled...
0
 
pmagonyAuthor Commented:
So the exchange server is SMTP enabled, the web server can't communicate with it via telnet, nor the web, where's the break down?  Tracing this down is a pretty excrutiating!  
0
 
Richard QuadlingSenior Software DeverloperCommented:
If you CANNOT telnet to the server using telnet server 25, then try the same command ON THE SERVER!!!!

If that is STILL not working, have you got XP SP2 and the built-in firewall enabled? Obviously, you will need to configure YOUR system to either turn it off or use GP to remove it from the LAN. With the external firewall and DMZ and a decent AV (we use McAfee) and WSUS, you should be able to control things a lot easier.

It is unfortunate that the TCP/IP protocol doesn't say WHY you can't connect. (e.g. server:25 denied via MS Windows XP SP2 Firewall on workstation)

0
 
Richard QuadlingSenior Software DeverloperCommented:
Software firewall on the server will also need to allow SMTP.

Another test.

Using Outlook Express (NOT Outlook), create an account to use SMTP to the Exchange Server. If OE cannot connect then the issue is most likely a firewall issue on your pc or the server on the LAN side.
0
 
pmagonyAuthor Commented:
RQ,

We set up OE ON our windows server and sent an email out to two of our inbox's and it succesfully went through.  Which means that the WINDOWS server is able to communicate to the Exchange server through port 25, through the DMZ, through the firewall...

But not from a PHP script with smtp server specified, port specified, username and password specified.

Here's a copy of my php script:

<?php
require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                   // set mailer to use SMTP
$mail->Host = "exch2k.xxx.team";  // specify main and backup server
$mail->SMTPAuth = true;              // turn on SMTP authentication
$mail->Username = "username";           // SMTP username
$mail->Password = "password";          // SMTP password

$mail->From = "mailtest@xxx.com";
$mail->FromName = "AquaCal";
$mail->AddAddress("user@xxx.com", "User Name");
//$mail->AddAddress("ellen@example.com");                  // name is optional
$mail->AddReplyTo("user@teamhorner.com", "Information");

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$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 = "RSVP Submitted; 25th Event";
$mail->Body    = "<h2>Someone has RSVP'd for AquaCal 25th Anniversary.  Their contact information is included below.</h2>" . "\nGuest 1: " . $_POST['fname1'] . " " . $_POST['lname1'] . "\nGuest 2: " . $_POST['fname2'] . " " . $_POST['lname2'] . "\nGuest 3: " . $_POST['fname3'] . " " . $_POST['lname3'] . "\nGuest 41: " . $_POST['fname4'] . " " . $_POST['lname4'] . "\nGuest 5: " . $_POST['fname5'] . " " . $_POST['lname5'] . "\n\nCompany: " . $_POST['company'] . "\nPhone: ". $_POST['phone'] . "\nEmail: " . $_POST['email'] . "\nI\We will attend: " . $_POST['keynote'] . "\nI\We will attend: " . $_POST['tours'] . "\nI\We will attend: " . $_POST['celebration'] . "\nInterested in Hotel information: " . $_POST['hotel'];
$mail->AltBody = "Text alternative... ALT BODY";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>

The error:

Warning: fsockopen() [function.fsockopen]: unable to connect to exch2k.xxx.team:25 (An established connection was aborted by the software in your host machine. ) in c:\PHP\includes\class.smtp.php on line 105
Message could not be sent.

Line 105 of class.smtp.php:
                                    $tval);   # give up after ? secs

mail option set to use SMTP, not sendmail or mail

--

Perhaps the error really isn't with fsockopen?  Do the files need to have any specific permissions?
0
 
Richard QuadlingSenior Software DeverloperCommented:
If you can't telnet to the port, you cannot use ANY other software.

OOI, why not use mail() rather than SMTP sockets?

I use PHP V5.0 running on XP SP2 via Sambar Server (dev machine) with Exchange 2003 on a Win 2K3 server. No problem.

I don't use phpmailer, I use HTMLMimeMail5 http://www.phpguru.org/static/htmlMimeMail5.html

My PHP.INI settings ...

SMTP = xxxx; The Exchange Server's name.
smtp_port = 25

; For Win32 only.
sendmail_from = richard.quadling@xxx.co.uk ; // Me


In my code ...

            ini_set('sendmail_from', 'BTCR@xxxx.co.uk'); // This script sends email on another users behalf.
            $objMail = new htmlMimeMail5Bandvulc();
            $objMail->setSMTPParams('10.0.0.7', 25);
            $objMail->setHeader('From', '"XXXX Tyre Contracts Rescue" <BTCR@xxxxco.uk>');
            $objMail->setHeader('Return-Path', '"XXXX Tyre Contracts Rescue" <BTCR@xxxxco.uk>');

Try telling phpmailer to use mail rather than SMTP.

0
 
pmagonyAuthor Commented:
If I was unable to Telnet exchange server, how was I able to set up a OE account and send mail through it using smtp settings?
0
 
Richard QuadlingSenior Software DeverloperCommented:
Good question.

Did you tell the OE that you were using secure SMTP? STMP is on port 25. Secure SMTP is on port 465 (SMTPS). This is probably why.

SMTP protocol over TLS/SSL (or so I'm told).

For SSL to work you will need to use a lot more code.

You MAY want to find your external SMTP server and send the internal mail to that.

Did you try the nslookup stuff I suggested?

Find the external mail exchange record for your domain (assuming the Exchange server also handles your external inbound email).

If the local exchange server does not deal with it, do you get external email on this server? If not, then you will HAVE to learn about SSL to do this.

0
 
pmagonyAuthor Commented:
OE's account was set up with standard settings (using port 25).  I was able to send new emails to my internal work address and my external personal address.

When I do an nslookup -q=mx mydomain.com i get:

mydomain.com MX preference = 10, mail exchanger = mydomain.com.mail5.psmtp.com
mydomain.com MX preference = 10, mail exchanger = mydomain.com.mail6.psmtp.com
mydomain.com MX preference = 10, mail exchanger = mydomain.com.mail7.psmtp.com
mydomain.com MX preference = 10, mail exchanger = mydomain.com.mail8.psmtp.com

mydomain.com.mail5.psmtp.com   internet address = 64.xx.5.xx

RQ, thanks for helping...
0
 
pmagonyAuthor Commented:
I just found out that the Windows Web Server is not a part of our domain.

Could these be causing all the above problems?
0
 
Richard QuadlingSenior Software DeverloperCommented:
If the webserver is outside your network, then you will need to send email to the appropriate mailserver using SMTP.

Choose one from the live above.

Or use my getmxrr replacement function for windows (getmxrr is not on windows).

function raqgetmxrr($sHostName, &$aMXHosts = NULL, &$aWeights = NULL)
      {
      $sNSLookup = shell_exec("nslookup -q=mx {$sHostName} " . DEFAULT_GATEWAY . " 2>nul");
      preg_match_all("'^.*MX preference = (\d{1,10}), mail exchanger = (.*)$'simU", $sNSLookup, $aMXMatches);
      if (count($aMXMatches[2]) > 0)
            {
            array_multisort($aMXMatches[1], $aMXMatches[2]);
            if (!is_null($aMXHosts))
                  {
                  $aMXHosts = $aMXMatches[2];
                  }
            if (!is_null($aWeights))
                  {
                  $aWeights = $aMXMatches[1];
                  }
            return True;
            }
      else
            {
            return False;
            }
      }


Returns the same as getmxrr() for non-windows.

See http://www.php.net/manual/en/function.getmxrr.php for full details.

The recent user note seems to completely ignore my post on this page.

Ho hum!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 9
  • 8
Tackle projects and never again get stuck behind a technical roadblock.
Join Now