3

I'm running XAMPP on my local machine and on a server in the office. Both are Windows machines.

I'm writing some code that uses mail() to send email from a form. By default, it uses sendmail.exe (which comes with XAMPP) to send the email. In all cases, the mail is actually sent via a third machine, which is the Exchange server.

From my local machine, PHP can send mail just fine. On the server, upon form submission I get this error:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp___port" setting in php.ini or use ini_set() in

... followed by my filename.

I don't understand why it's referencing "localhost." Nowhere in php.ini or sendmail.ini does is "localhost" used - I use the name of the mail server. The SMTP information used on both machines is the same.

As far as I can tell, the two environments have everything important in common:

  • The php.ini files are identical
  • The sendmail.ini files are identical
  • Both machines have the same version of XAMPP installed
  • The same batch script will run on both machines and successfully send email via sendmail.exe

I have stopped and started Apache several times to make sure it's using the updated config files.

When I get the error above, I notice that no log file is produced by sendmail.exe, which makes me think it's never run.

What am I missing?

Solved

My problem was that I thought it was using c:\xampp\php\php.ini, but it was actually using c:\xampp\apache\bin\php.ini. This should have been obvious, and I had previously edited the correct file on my local machine, but somehow I got confused when making the changes on the server.

Using php_info() showed me which config file was loaded, and I edited the correct one. It's working now! Thanks everyone for your help.

AnFi
  • 10,493
  • 3
  • 23
  • 47
Nathan Long
  • 122,748
  • 97
  • 336
  • 451
  • are you running another mail server like mercury that comes with xampp one one of the machines? – markus Aug 13 '09 at 22:16
  • this is still giving me hell.... can you reference how you set up your smtp settings on the iis? specifically the ones you had to chnage to get this running? – CheeseConQueso Aug 24 '09 at 19:52
  • @CheeseConQueso - I didn't mess with IIS at all. Apache (which came with XAMPP) is the web server; it uses the php.ini file in its \bin directory to control how it runs PHP code. In this case, the config file had to correctly specify the settings for PHP's mail() function. – Nathan Long Aug 25 '09 at 11:55
  • I wish I could use Apache... the setup is easier using that.. Thanks for the clarification anyway – CheeseConQueso Aug 27 '09 at 18:45

3 Answers3

2

You should add a call to phpinfo() in your page, and check that:

  • Your PHP script is using the correct php.ini
  • Check that the SMTP ini settings (as displayed in the phpinfo tables) are correct.
too much php
  • 88,666
  • 34
  • 128
  • 138
1

Try to use this in the code on server:

ini_set("SMTP","smtp.example.com" );
ini_set('sendmail_from', 'user@example.com'); 
Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
0

I had to do this also - you need to sent up the sendmail.ini:

Your sendmail.ini should be located in C:\xampp\sendmail\sendmail.ini.

You only need to be concern with 3 variables here:

1.smtp_server
2.auth_username
3.auth_password

Details are here: Send mail and xampp

Bill H

Bill H
  • 15
  • 2