Php – Sending Email by SMTP IIS7.5 via php site

emailiis-7.5PHPsmtptelnet

After my company decided to change the website we switched from old ASP.NET site to new website created in Drupal(php). The site is running locally on IIS7.5 and we also have virtual SMTP server on port 25.

The problem is that email can not be sent in new website (the old site is sending email. I don't know exactly how). The problem is not Drupal related because even with a simplest PHP script mail can not be sent.

The SMTP service seems to be running on TCP port 25 (checked with netstat command) but when I try

telnet localhost 25

I receive this message:

Could not open connection to the host, on port 25: Connect failed 

That error message was same when I run telnet 127.0..0.1 25 and telnet MERCURY 25

I created new VSMTP server on different port (28) and also configured approved relay and some other options.

  • Command telnet localhost 28 gives back blank page (after clicking any button I am getting back to the beginning)
  • Command telnet 127.0.0.1 28 gives back blank page also but
  • When I try `telnet MERCURY 28** finally the message I expected

    220 predrag Microsoft ESMTP MAIL Service, Version: 7.5.7600.16601 ready at  Fri, 3 Oct 2014 10:29:01 +0200 
    

What is happening here? What is the difference between these telnet commands? What is the setup I should do for my PHP.Ini file so I can send email with php website? I tried many different options but none of them is working.

Also from configuration we have McAfee antivirus, Windows firewall with open ports, the php version is 5.2, Windows Server 2008 R2 and my computer name is MERCURY.

Best Answer

For the service not working on port 25, it might be either that the service was configured but not actually started, or that something (an anti-virus or local firewall?) was preventing it from being reached on port 25 (here we have McAfee VirusScan and one of its features is actually blocking unlisted applications to connect to anything on port 25...). Do you have an anti-virus or other security software locally installed? Did you try restarting (either the SMTP server or the machine itself)? Did you check the startup log of the SMTP service (when configured on port 25) to see if there were any startup errors?

For the service working only with MERCURY (computer name) on port 28 and not with 127.0.0.1, it looks like the service is bound only to the network interface and not to the loopback one. This should be changeable in the configuration of your SMTP service, but if you don't find any option for that, you can just configure PHP to use MERCURY instead of 127.0.0.1 as server (although, if the server is only for local use, it would be much better to bind it only to the loopback interface, so it can't be reached from the network - avoiding exposing unused service is generally advisable as good practice to avoid security problems). Did you add 127.0.0.1 to the access list? (Check point #15 here: http://www.vsysad.com/2012/04/setup-and-configure-smtp-server-on-windows-server-2008-r2/)