Mail Function

Here is my code that I can't get to work

mail("", "My Subject", "Stuff");

in the php.ini file I have

[mail function]
; For Win32 only.
SMTP = localhost ; for Win32 only
; For Win32 only.
sendmail_from = ; for Win32 only
; For Unix only.  You may supply arguments as well (default: 'sendmail -t -i').
;sendmail_path =

It keeps giving me a server error on the mail function, what other settings do I need to change on the server or in the code?  I'm running win2000 server.  PHP works on this server I have many other pages that work, but this mail function won't run.  Any suggestions?
Who is Participating?
a.marshConnect With a Mentor Commented:
I basically wrote a function and placed it in a file of it's own:


  When migrating from Linux to Win2K, the PHP mail() function refused to work
  correctly with the "Default STMP Virtual Server" that comes with IIS5.
  This is a work around function that the system can use.

  It works by creating the actual email file that the SMTP server then picks up
  and delivers.

  The following inputs are expected:
  $emailBody - for Windows you must use "\n\r" not just "\n" for new lines.

  Author: Ant Marsh
  Version: 1.0.0
  Date: 2001-03-08
function iis_mail($emailTo, $emailFrom, $emailSubject, $emailBody){
 $file = fopen( "c:\inetpub\mailroot\pickup\message.eml", "w");
 fwrite( $file, "To: $emailTo\n\r");
 fwrite( $file, "From: $emailFrom\n\r");
 fwrite( $file, "Subject: $emailSubject\n\r");
 fwrite( $file, "\n\r");
 fwrite( $file, "$emailBody\n\r");
 fwrite( $file, "\n\r");
 fclose( $file );

 return true;


and then just included the file in any other php script that needed it.

You will need to change:


if IIS is not setup on your c: drive.

you must configure the SMTP server.
this is the server which is use to send mail
if you have an ISP you can use or something like that
perhaps you can start an SMTP server on Windows 2000 but it's not installed in the default installation

stainAuthor Commented:
It is running, I can built and ASP page on the same server and mail just fine.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

I gather you are using the SMPT service with IIS5?

I had this issue but I did come up with a work around for it by writing my own mail function.....let me find it for you.


Ditch windows 2000 and install linux. This is one of the many and myriad problems you will encounter trying to serve a site via Win2000. It's NOT a server.  It crashes, it has nice graphical windows which kill your speed, it hides things from you with no documentation to help you find them.
Hi stain this is a common problem with the mail function
in php.ini tut this..

instead of SMTP = localhost ; for Win32 only

put the ip address of the server on the network where there is smtp service ...for ex exchange server

SMTP= as we have here ...
mine is working fine...

If it still doesn't buddy
   then tere is one and only one solution...

 shift to your page on linux may be redhat

            regards Anup
a.marshCommented: solution works fine - I've used it after developing a system on Linux and then the client having the system hosted on a Win2k server with IIS5


Any feedback stain?

It's time to clean up this topic area and that means taking care of this question. Your options at this point are:

1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.

2. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

3.  Ask Community Support to help split points between participating experts.  Just comment here with details.

4.  Delete the question because it is of no value to you or to anyone else.  To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

If you elect for option 2, 3 or 4, just post comment with details here and I'll take it from there.  We also request that you review any other open questions you might have and update/close them.  Display all your question history from your Member Profile to view details.



Hi Experts:

In the event that the Asker does not respond, I would very much appreciate your opinions as to which Expert ought to receive points (if any) as a result of this question.  Likewise, you can also suggest that I PAQ or delete the question.

Experts, please do not add further "answer" information to this question.  I will be back in about one week to finalize this question.

Thank you everyone.

Moondancer :)
Community Support Moderator @ Experts Exchange

P.S.  REGARDING POINTS, Guidelines and more:  
I stand by my solution.

Finalized by:
Community Support Moderator @ Experts Exchange
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.