2

I want to make mail() of PHP work in my Windows Server 2012 R2. To this end, I first installed SMTP by following this page.

One thing that confuses me is the Full-qualified domain name. WIN-RFELH8GM0KN is what it proposes by default. My server hosts several websites, does anyone know which website I should specify here?

I did not change this, as a consequence, mail www.google.com in nslookup returns DNS request timed out. So is it an error?

enter image description here

Of cause, my test.php does not send the mail:

<?php
mail('mymail@gmail.com', 'title', 'content');
?>

Could anyone help?

Update 1 Following the answer of @LittleAI , I started SMTP, but DNS request timed out is still there:

enter image description here

Update 2 Here is php.ini:

enter image description here

telnet localhost 25 returns the follows:

enter image description here

Update 3 Here was a test, which worked well: I did receive the test mail in the inbox of softtitmur@gmail.com. However, if I redo the test in Update 1, there is still DNS requested time out.. And test.php still cannot send the mail...

enter image description here

Update 4 I just realised that in the page I followed, it is mail.vsysad.com under nslookup (I thought it was mail vsysad.com, that is why i tried mail www.google.com which did not make sense). So it works also in my server, and there is no DNS request timed out.

enter image description here

Then, I double checked php.ini, I realised that sendmail_from was not uncommented. So I uncommented it and set sendmail_from = softtimur@gmail.com, as a result, mail() of php works now, so the problem is solved, though I still don't understand FQDN and its default value (ie, WIN-RFELH8GM0KN)...

SoftTimur
  • 5,630
  • 38
  • 140
  • 292

1 Answers1

0

The first thing I noticed is that your SMTP Virtual service in IIS is not in a starting state so this would cause an issue. Make sure this service is in a starting state before testing.

The FQDN name is mainly used for the SMTP banner which the sender will be presented when connecting over port 25 to your server.

It maybe worth installing the DNS role onto your server and create a forward lookup zone referencing a fake domain e.g test.com and create an a record within this zone called SMTP using your servers IP. Make sure to then set your server to use 127.0.0.1 as the DNS provider so it can check record before delegating the reponse to root hints/external dns forwarder.

You need to do an SMTP request using Telnet to confirm SMTP is listening on port 25. You can do this by using the localhost ip address (127.0.0.1) as shown below:

  telnet 127.0.0.1 25
  helo test.com
  MAIL FROM: ****YOUR EMAIL ACCOUNT****
  RCPT TO: ****SENDERS ADDRESS****
  DATA

You would probably not receive the email from your relay to GMAIL due to SPF Record which is in place that only allows certain IP/hostnames to send as google.com, but for testing you should see your server receive the mail after data has been inputted.

Here is the guide for using telnet on your server. Just make sure you have telnet feature installed as this is not installed by default.

http://www.yuki-onna.co.uk/email/smtp.html

Additional:

 telnet localhost 25

After the SMTP banner type the following command in but make sure not to make any mistakes or else you'll need to probably start your sesssion all over again.

 helo test.com

You should then see a 250 response to say the server is listening

The type the following:

MAIL FROM: test@test.com

It should respond with OK. If so, then type:

RCPT TO: ***YOU EMAIL ADDRESS OF CHOICE****

Again, it should respond with OK. If so, type the following:

DATA

Press enter after the DATA command. Your now into the body of the email. For testing purposes we will miss the subject bar and just add some data to the body.

  This is a test email.

Then to complete the email you need to leave a blank line by pressing return, then a full stop, then return again like so.

    ***BLANK LINE****
    .
    ***Hit Return****

Screenshot all the commands but you can blank out the email so I can see the output.

Kitson88
  • 2,889
  • 5
  • 22
  • 37
  • Thanks for your answer, but the part except starting SMTP is really hard to understand. I started the SMTP but the error is still there (please see the update in the OP). I just want to make `mail` of `php` work, could you tell me the mandatory steps to realise this? – SoftTimur Sep 27 '16 at 16:20
  • 1
    I'll help and I'm sure we will get this sorted. Can you confirm if your PHP.ini settings on your windows server are configured to use localhost. [How to configure PHP SMTP mail settings Link](http://www.php.net/manual/en/mail.configuration.php) – Kitson88 Sep 27 '16 at 17:23
  • Can you also confirm if the server is listening on port 25? You can do this by typing the following command in command prompt 'telnet localhost 25' – Kitson88 Sep 27 '16 at 17:25
  • Okay thats good, I can see the SMTP banner which is the same as the Fully Qualified Domain Name and it's accepting requests on 25 which is perfect. If possible, can you test that mail is sending via telnet? You can do this from CMD or Powershell (which I can see that your using). Type in the following: – Kitson88 Sep 28 '16 at 08:57
  • See my answer for steps to test. – Kitson88 Sep 28 '16 at 09:11
  • Please see my update... Btw, should I install DNS server? – SoftTimur Sep 28 '16 at 23:48
  • Thats good news. We understand that SMTP is accepting requests from localhost on port 25 so there is not an issue with your relay. The issue seems to be with your WAMP or XAMPP setup. Can you confirm what PHP software you are using for hosting PHP. With regards to your NSLOOKUP in powershell, what are you trying to achieve by typing in 'mail www.google.com' ? Also, no need to install DNS server role as your server is working fine and able to resolve external requests. I know this because your email would not of send to gmail without doing some form of MX lookup (DNS Query for mail). – Kitson88 Sep 29 '16 at 17:39
  • Please see my update... So the key is to not forget to set `sendmail_from` to make `mail()` work. Thanks for your help, which let me know how to use `telnet` to test SMTP... – SoftTimur Sep 30 '16 at 02:04
  • Great news! I'm glad its working for you and thanks for sharing the exact fix. – Kitson88 Sep 30 '16 at 11:12