I wanted to share with the community a work around we have developed for using the mail function within PHP when compiled with NSAPI (Iplanet SunOne).
Quick summary of the problem.
Description:
------------
mail() stops working a few minutes after Sunone 6 web server starts,
which makes this look like a resource problem...
Config line: "./configure --with-mysql=/usr/local/mysql
--with-nsapi=/home/netscape/servers --enable-track-vars --enable-libgcc
--with-ldap"
Note that mail() does work briefly after web server is restarted so it
doesn't seem to be a configuration problem.
Reproduce code:
---------------
<?php
mail("karthur@kzoo.edu", "Test Subject", "Test Body");
?>
Expected result:
----------------
expect to receive an email
Actual result:
--------------
no email received
I get no php or system errors but the following error shows up in the
IPlanet logs:
"trying to GET /is/sys
net/test/email.php, php4_execute reports: PHP Warning: mail(): Could
not execute
mail delivery program '/usr/lib/sendmail -t'"
Solution:
Here's a solution that appears to work for us so far. It might be nice
if the php developers would consider a --with-sfio parameter in
configure that took care of this. Our exec command is still broken so
I'll probably have to do this same type of thing for that.
1. install sfio from AT*T
2. setenv LIBS "-L/usr/local/lib/sfio -lsfio"
3. modify ext/standard/mail.c
4. modify /usr/local/include/sfio/sfio.h so references to other sfio
header files are absolute paths (if I use -I/usr/local/include/sfio to
find the files it produces errors for files other than mail.c)
5. run configure and compile as normal
here's a diff or my code and the original mail.c:
diff mail.c mail.c.orig
23c23
< #include </usr/local/include/sfio/sfio.h>
---
#include <stdio.h>
177c177
< Sfio_t *sendmail=NULL;
---
FILE *sendmail;
215c215
< sendmail = sfpopen(sendmail, sendmail_cmd, "w");
---
sendmail = popen(sendmail_cmd, "w");
224c224
< sfclose(sendmail);
---
pclose(sendmail);
228,229c228,229
< sfprintf(sendmail, "To: %s\n", to);
< sfprintf(sendmail, "Subject: %s\n", subject);
---
fprintf(sendmail, "To: %s\n", to);
fprintf(sendmail, "Subject: %s\n", subject);
231c231
< sfprintf(sendmail, "%s\n", headers);
---
fprintf(sendmail, "%s\n", headers);
233,234c233,234
< sfprintf(sendmail, "\n%s\n", message);
< ret = sfclose(sendmail);
---
fprintf(sendmail, "\n%s\n", message);
ret = pclose(sendmail);
This information has also been posted on the PHP forum at
http://bugs.php.net/bug.php?id=28748
We had a heck of a time finding much information about the exec and mail not working on Solaris so we wanted to share this with everyone. Hope it helps someone out!
Cheers,
Ken and David
Kalamazoo College