tags:

views:

180

answers:

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.

A: 

Try to use this in the code on server:

ini_set("SMTP","smtp.example.com" );
ini_set('sendmail_from', '[email protected]');
Juicy Scripter
A: 

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
+2  A: 

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