Mail Function

Posted on 2001-07-05
Last Modified: 2006-11-17
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?
Question by:stain
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 6257321
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


Author Comment

ID: 6257421
It is running, I can built and ASP page on the same server and mail just fine.
LVL 15

Expert Comment

ID: 6257542
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.


Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

LVL 15

Accepted Solution

a.marsh earned 100 total points
ID: 6257554
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.


Expert Comment

ID: 6275074
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.

Expert Comment

ID: 6275883
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
LVL 15

Expert Comment

ID: 6276148 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


LVL 15

Expert Comment

ID: 6282307
Any feedback stain?


Expert Comment

ID: 6419130
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:  
LVL 15

Expert Comment

ID: 6420026
I stand by my solution.


Expert Comment

ID: 6446530
Finalized by:
Community Support Moderator @ Experts Exchange

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
php error 27 58
Make login page safer 3 33
Compiling PHP with Curl plus protocols 8 25
How to get chosen background-color on every line? 10 21
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question