I'm trying to get the mail() function to work but running into problems. I have SMTP set to localhost and smtp_port set to 25
then I'm saying

$m=mail('me@hotmail.com','failed login attempt','failed login attempt','From:test@test.com');

and then checking 1) to see if I get the mail, and 2) the value of $m which is zero. What should be the next thing to check? I saw something about an smtp app, which I don't know if I have or not.

    Try running the following script, and search its output for more information about your server's mail configuration:

    <?php
    
    phpinfo();
    
    ?>

    HTH,

      In php info we have
      sendmail_from "no value"
      sendmail_path "no value"
      internal sendmail support for windows "enabled"

      What else should I look for, and is there something I need to change about these?

        Try setting those values with ini_set() in your script. I had to do that a while back on a win32 server once to get the mail() function to work...

          Sorry to butt in on the topic but thought i'd post my question here instead of starting a new thread.

          Ermm... i too have a query about the mail() function

          How do i add a link in the body of the message i am sending?

          So far i have:

          "Dear user. thank you for signing up to the forums"

          How would i make the word 'forums' a link to www.blabla.com/Forum.php??

          Thanks, BIOSTALL

            I think you need to add "Content-Type: text/html" to the headers, this tells the mail program to interpret as html rather than plain text. Of course I don't really know because I can't send mail at all but that's what I've seen said.

            "Try setting those values with ini_set() in your script."
            Any advice on what they should be set to?

              Yep. use the Content-Type mail header and set to text/html is correct...however, beware, many spam filters will block HTML-only email messages...make sure you test before you deploy ....

                Originally posted by hwttdz
                In php info we have
                sendmail_from "no value"
                sendmail_path "no value"
                internal sendmail support for windows "enabled"

                What else should I look for, and is there something I need to change about these?

                Note: The Windows implementation of mail() differs in many ways from the Unix implementation. First, it doesn't use a local binary for composing messages but only operates on direct sockets which means a MTA is needed listening on a network socket (which can either on the localhost or a remote machine).

                originally posted by id10t
                Try setting those values with ini_set() in your script. I had to do that a while back on a win32 server once to get the mail() function to work...

                IIRC, you need to set SMTP_HOST (or something like that) in php.ini . . . you might find the comments in php.ini to be of some assistance with this. 🙂

                  Try this simple test....

                  echo out your mail() call.

                  If it pirnts a "1" you're server is fine.

                  If it prints a "0" you need to re-configure/enable sendmail

                  ...atleast it will keep you from trying to fix something that isn't broken and get you going in the right direction.

                    We definitely have a 0.

                    SMTP_host is set to localhost, which I think is what I want
                    SMTP_port is set to 25 which again is I think correct.

                    Of course it doesn't work so these may not be correct. About the other values that I mentioned that are not set, do I need to set those. And what does IIRC mean?

                      If I recall correctly, that's what it means.

                      Hmm, recursion? I could've done better, methinks...

                      Your problem could be any number of things. Are you sure there's an MTA running on the localhost? Is PHP running in safe mode (if so, [man]mail/man won't work!)? What about permissions/user rights, over-restrictive anti-spam/relaying policies (not that those are always bad), firewall configuration . . . it goes on and on.

                      If this is your box, you're got some definite seat work to do; if it's a "hosted" server, it dial-n-hold time . . . 🙁

                      [edit]Incidentally, Windows doesn't come with SMTP service by default. They want you to buy Exchange 😉[/edit]

                        This is my box. I don't know what an MTA is? I have safe_mode=off in php.ini. Does firewall affect localhost, even if it wasn't reaching the inbox due to anti-spam shouldn't mail return 1 if it gets sent. I don't know about permissions/user rights what do I need to check there.

                          since it's your box, I'm sure you can open a terminal....

                          try the following: the # denots the terminal prompt be sure to enter a period on a line by itself at the end of the message body to denote it's finished.

                          mail youremail@host.com <press Enter>

                          Subject: enter your subjext <press Enter>
                          type your message body
                          . <press Enter>

                          see if you get the message.

                            Open a terminal? as in be in the directory of php. I'm sorry I don't know this.

                            In the directory of php I get 'mail' is not recognized as an internal or external command.

                              windows xp professional. If you want version information you're going to have to tell me how to fetch that.

                                Run "cmd" on your machine, and enter the command "netstat -an".

                                Search the output for a LISTEN directive that appears on port 25, perhaps like (off the top of my head, no Winbox handy)

                                22.33.44.55:25   LISTEN

                                If your machine is listening on port 25, most likely you do have a working "Mail Transfer Agent". Like I noted above, Windows doesn't have one built in. If you don't have an MTA, you'll need to either install one on this box or set your SMTP_HOST variable in php.ini to a machine that does have a running MTA ... maybe your upstream provider's mailserver?

                                  right...if you install linux or unix, they come installed with an internal sendmail server so setting SMTP to localhost indeed work...since you are running wihdows, do as suggested...install an SMTP server on your box or use your ISPs' mail server (if they'll allow you to do so)

                                    No listening on 25, so I need to install an SMTP server or use an ISP mail server. So if I have outlook setup the ISP mail server would be the incoming server?

                                    Are there any freeware SMTP servers?

                                    There's no chance that there is a free server that has this mail capability, is there?

                                      Originally posted by hwttdz
                                      No listening on 25, so I need to install an SMTP server or use an ISP mail server. So if I have outlook setup the ISP mail server would be the incoming server?

                                      Are there any freeware SMTP servers?

                                      There's no chance that there is a free server that has this mail capability, is there?

                                      I imagine so. Googling "Windows SMTP Server Freeware" gives me 606,000 results, one of which might actually work.

                                      The server you want in your Outlook config is the "Outgoing" (SMTP) server.

                                      Have a good day; I hope we've been of some assistance to ya! 🙂