Solved

Mail Function

Posted on 2001-07-05
11
167 Views
Last Modified: 2006-11-17
Here is my code that I can't get to work

<?php
mail("myemail@something.com", "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 = anything@something.com ; 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?
0
Comment
Question by:stain
11 Comments
 
LVL 1

Expert Comment

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

0
 

Author Comment

by:stain
Comment Utility
It is running, I can built and ASP page on the same server and mail just fine.
0
 
LVL 15

Expert Comment

by:a.marsh
Comment Utility
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.

:o)

Ant
0
 
LVL 15

Accepted Solution

by:
a.marsh earned 100 total points
Comment Utility
I basically wrote a function and placed it in a file of it's own:

<?php

/*
  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:
  $emailTo
  $emailFrom
  $emailSubject
  $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:

c:\inetpub\mailroot

if IIS is not setup on your c: drive.

Ant
0
 

Expert Comment

by:roglewis
Comment Utility
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.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Expert Comment

by:anupkarade
Comment Utility
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=  200.0.0.9 as we have here ...
mine is working fine...

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

 shift to linux..run your page on linux may be redhat


            regards Anup
0
 
LVL 15

Expert Comment

by:a.marsh
Comment Utility
Nonsense........my 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

:o)

Ant
0
 
LVL 15

Expert Comment

by:a.marsh
Comment Utility
Any feedback stain?

Ant
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
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.

PLEASE DO NOT AWARD THE POINTS TO ME.

____________________________________________



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:  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp  
0
 
LVL 15

Expert Comment

by:a.marsh
Comment Utility
I stand by my solution.

Ant
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
Finalized by:
Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now