I installed PHP 4.2.2 on a Win2K server running IIS 5. PHP is configured as cgi.

Everything works great except that an error occurs when the mail function "mail()" is invoked.

The mail function is configured correctly

<?
mail("me@mydomain.com","Test Email","This is a test\n","From: someone@mydomain.com");
?>

But, the resulting page shows an error at the exact line number where the mail function begins...

Server Error: Line 34....

Below is a copy of the smtp info from the php.ini file...

[mail function]
SMTP = localhost ;for win32 only
sendmail_from = me@localhost.com ;for win32 only

Has anyone here had this problem? What am I missing? Does Win2K and IIS require additional software to be installed for this to work?

Thanks for any assistance you can provide.

    Okay, let me simplify my question.

    On Win 2000 and IIS, does the standard install include SMTP service or is it necessary to add software so that programs written in PHP can use the mail() function?

      Hi.

      IIS5 does indeed come with an SMTP server.

      My guess is that the server may not be running, or that its domain has not been set. It does not set itself to the host name automatically. It just calls itself 'Default Domain' or something equally as silly.

      HTH

      Neil.

      P.S.
      I am located in the UK.
      And we aren't being silent.
      🙂

      N+++

        Neil, the British are our only true allie in Europe, in my opinion, except for the Poles and some of the other former East block nations. I just don't know what happened to the Western Europeans. It's as if they have stuck their heads in the sand.

        Take care now.

          I find the following URL occasionally helpful:

          http://www.microsoft.com/technet/treeview/default.asp?url=/technet/prodtechnol/iis/reskit/iis50rg/introiis.asp

          The SMTP Service is an option when you install IIS 5.0. Referring to the SMTP Server as localhost (once it is running) may not work. You might need to refer to a Fully Qualified Domain Name once you have the server running. I like to register an A-Record or CName in DNS to make things a bit easier. Something like smtpphp.yourdomain.com.

          Provided that your DNS admin is a friendly kind of guy...

          I also know that you need to configure the SMTP server via the Microsoft Management Console with respect to who has access to the server.

          I hope this helps.

          Cheers,

          Gordon

            The mail function under windows is buggy.

            Instead of using localhost as the smtp, use the something like smtp.yourisp.com. But even that does not guarantee success.

            Unless you have a mail server running on localhost, always use the smtp server address.

            Also, instead of me@localhost.com, use me@yourisp.com. Some isp's filter out any outgoing mail that does not carrry the isp's domain name.

            Make sure you configure Outlook, and then use the same config info inside your php.ini.

            If mail() still does not work, try sockets. Below is a sample code...

            function sendmail($name, $from, $to, $subject, $body, $html, $charset ) {
            $smtp_server = "smtp.yourisp.com"; //enter your smtp server here
            if (!$smtp_sock = fsockopen("$smtp_server", 25)) {
            die ("Couldn't open mail connection to server! \n"); }

            fputs($smtp_sock, "HELO $smtp_server\n");
            fputs($smtp_sock, "VRFY $smtp_server\n");
            fputs($smtp_sock, "MAIL FROM:<$from>\n");
            fputs($smtp_sock, "RCPT TO:<$to>\n");
            fputs($smtp_sock, "DATA\n");
            fputs($smtp_sock, "From: $name($from)\n");
            fputs($smtp_sock, "X-Mailer: emailer1.0\n");		
            if ($html) 
            	fputs($smtp_sock, "Content-Type: text/html;");		
            else
            	fputs($smtp_sock, "Content-Type: text/plain;");		
            fputs($smtp_sock, "charset=$charser\n");	
            fputs($smtp_sock, "MIME-Version: 1.0\n");	
            fputs($smtp_sock, "Subject: $subject\n");
            fputs($smtp_sock, "To: $to\n");
            fputs($smtp_sock, "$body");
            fputs($smtp_sock, "\n.\nQUIT\n");
            fclose($smtp_sock);

            }

            $name = "Your Name";
            $from = "YourEmail@yourisp.com";
            $to = "recipient@domain.com";
            $subject = "Enter a subject here!";
            $body = "Include your email body here";

            sendmail($name, $from, $to, $subject, $body, 1, "euc-kr");

            Goodluck.
            Richie.

              Thanks for the response! This is very informative and the best information I have received from this list so far.

              Originally posted by wscreate
              I installed PHP 4.2.2 on a Win2K server running IIS 5. PHP is configured as cgi.

              Everything works great except that an error occurs when the mail function "mail()" is invoked.

              The mail function is configured correctly

              <?
              mail("me@mydomain.com","Test Email","This is a test\n","From: someone@mydomain.com");
              ?>

              But, the resulting page shows an error at the exact line number where the mail function begins...

              Server Error: Line 34....

              Below is a copy of the smtp info from the php.ini file...

              [mail function]
              SMTP = localhost ;for win32 only
              sendmail_from = me@localhost.com ;for win32 only

              Has anyone here had this problem? What am I missing? Does Win2K and IIS require additional software to be installed for this to work?

              Thanks for any assistance you can provide.

                6 days later

                I just fixed this:

                As mentioned before I changed the SMTP host from localhost to a queslified name.

                Now on the SMTP server:

                • open the IIS Manager
                • launch the properties dialog for the Default SMTP Virtual Server
                • Under the Access tab, click the Relay... button
                • Make sure the Only the list below option is selected, click Add... button and enter the IP address of the server
                • Click OK and then OK again

                That worked for me =)

                  Write a Reply...