I'm having a similar problem.

I'm running Apache 1.3.19 and PHP 4.0.5 on a Windows 2000 Professional machine. This PC is on a Windows Network corporate LAN. I have installed a Windows port of the UNIX sendmail program, configured it to use www.webmail1.com as my SMTP host, set the path (c:\sendmail) in my Windows path line, and successfully tested it from the command prompt. However, PHP is unable to connect using the mail() function. I have tried both:

SMTP = localhost

and

SMTP = www.webmail1.com

in my php.ini file. Here is the relevant code (all on one line):

mail($email, $subject, $message, "From: $adminmail\nX-Mailer: PHP/" . phpversion());

This gives me a "Failed to connect" error message. What should I do?

    You could try the IP address for webmail1.com or simply "webmail1.com" for your SMTP setting in PHP.ini. Mine is currently set to my server's name and it also works when it is set to my internal IP address. Obviously, your situation is slightly different since you are using an external SMTP host.

    As I mentioned before, I eventually determined that my problem was actually due to the header parameter in the mail() function. Try using the mail() function without headers:
    mail($email, $subject, $message, "");

    If it sends without specifying headers then you have found your problem. You may have to also of course experiment with different settings for SMTP in the ini file until you get it. As soon as I tried to send without headers it worked and I stopped getting the "Failed to connect" error. Then I just had to figure out the correct language for the header parameter.

    Here is an example of my code:

    $THeaders="From: My Company <info@company.com>\r\nTo: $name <$email>\r\nReply-To: My Company <info@company.com>\r\nContent-Type: text/plain";

    mail($email, $TSubject, $TMessage, $THeaders);

    Notice the "\r\n" used in the header setting instead of just "\n". I'm not sure but I think I read this is necessary for Windows based usage. Maybe this can help you. Let me know if you have any luck.

    Brian

      Brian,

      I tried it without the headers, and I tried SMTP = webmail1.com and SMTP = [webmail1 IP address], but neither of these worked. I've also tried copying all the sendmail files (sendmail.exe, sendmail.ini, etc.) to the Apache bin and cgi-bin folders and restarting Apache. PHP still can't connect.

        Brian,

        I found my problem. It was a stupid mistake, so feel free to pelt me with rocks and garbage!

        The problem was, I've been editing the php.ini file in my PHP folder instead of the one in C:\WINNT all this time. Duh!

          Good to hear. I was really at a loss after my last suggestion didnt work. I'm new to PHP but starting to pick it up slowly but surely. At least we have a place to come and find help or help each other. Good luck.

            I'm new to PHP, too. My first PHP/DHTML applet can be seen at:

            binaryprophets.omplace.com

            Click "Demo 2" to see the applet. It originally used MySQL, but my host wanted money to add a database, so I changed it to flat (text) files, one for each tab. Each demo works in Netscape 4.77 individually, but something went wrong when I combined them into one document; thus, you'll have to view it in MSIE till I fix it. Demo 1 & 2 are the only working sections so far. The rest is under construction.

              Hello,

              We have been having problems as well and your setup is pretty much like ours.

              Which "port" of sendmail did you use?

              Also, we have noticed a problem with emails more then 1000 characters long ... have you had this problem?

              Thanks in advance.

              David

                It's a 30-day trial version from www.indigostar.com that I've installed on my workstation for testing. I think they've renamed their commercial version IndigoMail. This should function identically if you're looking for a permanent Win32 solution (beyond 30 days).

                Fortunately, our site will eventually end up on a UNIX server, so there's no need for me to use this version beyond the trial period. 🙂

                  I have not had this problem, since my script only uses sendmail to send new users their password when they sign up.

                    Greets,

                    Yea ... that's the one I found and I installed it and it worked great ... till I ran into the 1,000 character limit thing ... but that, we found out, is due to php and not the sendmail product.

                    Good luck with the switch to Unix ... we are are NT for the duration for now, since we are better at managing NT servers then *nix servers.

                    David

                      Not to worry on the UNIX move - I just upload the files and let the administrator worry about his server. 😉

                      By the way, what explanation did you find for the 1000 character limit when using the PHP mail() function?

                        Greets ...

                        Here is the programmers note on the first time it was reported ... although this was reported as a 2,500 character limit.

                        --snip--
                        [2001-06-22 18:31:34] hholzgra@php.net
                        windows mail code badly needs a rewrite
                        --snip--

                        So ... it's been around for a while ... don't know when/if it's going to get fixed ... although I do know that my 4 month old puppy is getting fixed today :-). (ouch, that's gotta hurt).

                        David

                          6 days later

                          did you know Sendmail do a fully supported product for NT now - check out the sendmail.com website - either that or the org or net - one of those three - i was interested in getting it and although it's not free - combines a powerful MTA with NT clients ...

                            8 days later

                            Sounds cool! I've already moved the site to our UNIX box, though.

                              4 months later

                              Hi all,

                              I wanted to be able to send mail from my W2K box so I configure SMTP virtual server (which is supposedly for this purposes) as follow:

                              • config (a): take all the default (someone said it will work with just default setting).
                              • config (b): assigned IP (my W2K IP), assigned relay host (my ISP SMTP server), assigned smarthost (also my ISP SMTP).

                              In best case, it was able to pickup mails from pickup directory only to drop back to Drop directory with Undeliverable notice (unable to deliver to destination).

                              Questions: anyone has better luck doing the same thing or are there better way to achieve the same purpose?

                              Thank you,
                              -Pete

                                Write a Reply...