用php发送电子邮件

I am trying to send mail from my site.But its not working now. Can you please tell what all changes should I make in php.ini configuration file for achieving this functionality? Using windows OS. Here is my code for your reference.

     $to = "name@gmail.com";
     $subject = $subject;
     $body = $message;
     if (mail($to, $subject, $body)) {
           echo("<p>Message successfully sent!</p>");
     } else {
           echo("<p>Message delivery failed...</p>");
       } 

There may be a lot of things wrong, but for starters, the PHP manual for mail() says:

When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing.

You're not setting the From header in your code, so that would be the first thing to check.

(Also: $subject = $subject; is odd.)

Windows doesn't contain an sendmail like Linux does.

So for Windows you have to provide an SMTP server: http://www.geeklog.net/faqman/index.php?op=view&t=19

Try setting these as well.

           $headers = "MIME-Version: 1.0
"; 
           phpini_set("sendmail_from", "info@mydomain.com"); // at the beginning of yoru script