Link to home
Start Free TrialLog in
Avatar of jeffers
jeffers

asked on

PHP mail() function not working

I'm experiencing a strange situation on my FreeBSD web server. About two months ago when I first set it up, I tested PHP's mail() function, and it worked fine. Recently, when I tried to impliment a script that used it, it wouldn't work. No error message is given in reply, and I'm having a tough time figuring out where in the world to start. I'm far from a sendmail/unix expert. The sendmail daemon is running, and I've tried restarting it with no effect. The performance of the script doesn't change whether it's running or not (never gives an error message). Any ideas on what I could try to diagnose the problem?

-Jeff
ASKER CERTIFIED SOLUTION
Avatar of NetWize
NetWize

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tconnolly
tconnolly

I had a similar problem where I was hosting several sites with a host, and on one site, the php mail() function worked and on another, it didn't. The only discrepancy I could find between the different servers was the version of PHP. The server with 4.2.2 worked but the ones (i tried more than one) with 4.2.3 did not. I can only imagine it had something to do with configuration or the upgrade when installed, but just a couple of pennies for ya.

Hope this helps :)
Tom Connolly
Hey jeffers,

Also check your php.ini file for your sendmail path.
You can also find this via the phpinfo() function.

E
Avatar of jeffers

ASKER

I tried to use "mail user@host.com", and at the end I get the following error, which I also get using the sendmail command directly:

can not chdir(/var/spool/clientmqueue/): Permission denied
Program mode requires special privileges, e.g., root or TrustedUser.

lrwxrwxrwx  1 root   wheel .. /usr/sbin/sendmail -> /usr/sbin/mailwrapper
-r-xr-xr-x  1 root   smmsp .. /usr/sbin/mailwrapper
drwxrwxrwx  2 smmsp  smmsp .. /var/spool/clientmqueue

I found some about this on google, and it said to set sendmail's GID to smmsp, but didn't mention that sendmail was a link. I tried setting the link's GID, but it just stays "wheel". I did change mailwrapper's GID to smmsp, but that had no effect on the error message.
One of the criticisms I voice over and over again is that minor releases of PHP result in seemingly needless changes to APIs and functionality.  Often these changes are undocumented and developers don't see problems until they take a working code set to a different version of PHP.  I've experienced major headaches when I upgraded PHP from 4.0.2 to 4.1.1 on a server with running applications.  Or even worse going from 4.1.3 to 4.2.1.  In some cases parameter lists of established functions actually change.

I experienced problems with sendmail() on a windows environment.  If attachments were >3889 bytes the sendmail() function would just crash the process, not producing any error.  I would see no error log messages, nothing in the SMTP server, and nothing on the browser (nor an e-mail).  After taking apart the _source code_ for PHP i noticed the sendmail() function had some code written just for windows that limited the size of the header parameter to 4K bytes.  That seemed to be the culprit, it was reproduced, and hopefully it's been fixed (but I don't know).  After many tries at different workarounds I ended up just writing the RSC-compliant text to a file and then called a DOS program to send that file as e-mail.  There are third-party products that I could've bought as an alternative and used within PHP much like sendmail() - but I didn't have the money...
Avatar of jeffers

ASKER

I finally resolved the problem with the following:

cd /usr/src/etc && make DESTDIR=/ distrib-dirs

Thanks everybody for the tips that helped me find the solution.