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.


Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

717 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