Re: [PHP4BETA] mail() doesn't work : bug ?
| From: | Olivier Cahagne | Date: | Thu, 11 Nov 1999 03:25:41 +0000 |
| Subject: | Re: [PHP4BETA] mail() doesn't work : bug ? | ||
| References: | 1 2 3 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-6128@lists.php.net to get a copy of this message | ||
> > > I'm not too familiar with FreeBSD's system call tracer, but try something
> > > like this:
> > >
> > > truss -f ./php -f testscript.php 2> trace.out
> > >
> > > Then you can look for "exec" in strace.out and see if sendmail is
> > > exec'ed
> > > and what parameters it gets, or if it fails.
> >
> > Sorry, there's no truss on the NetBSD box I have access to (either it
> > doesn't exist or root didn't install it).
> > man truss -> man trace but trace doesn't seem to exist neither.
> then try looking for one of : strace, ltrace, gdb
How would you debug it ? Should I hard code sendmail_path or anything
else in mail.c ?
BTW, I extracted the following code from php-4.0b2/ext/standard/mail.c
and compiled it separately.
---- mail.c ----
#include <stdio.h>
void main()
{
FILE *sendmail;
int ret;
sendmail = popen("/usr/sbin/sendmail -t", "w");
if (sendmail)
{
fprintf(sendmail, "To: %s\n", "cahagn_o@epita.fr");
fprintf(sendmail, "Subject: %s\n", "test");
fprintf(sendmail, "\n%s\n", "test body");
ret = pclose(sendmail);
}
else
{
printf("nope\n");
}
}
---- snip mail.c ----
This won't send any mail, my (temporary) solution follows below :
Another thing I don't understand is popen always returns 1 even if it
doesn't find sendmail (it says however "command not found") : I tried to
set sendmail_path to /usr/sbin/foo and mail() returns 1.
Solution, to actually send a mail successfully, I have to add the
recipient right after sendmail :
sendmail = popen("/usr/sbin/sendmail -t", "w");
is replaced with:
sendmail = popen("/usr/sbin/sendmail cahagn_o@epita.fr", "w");
This works. It sends a mail. It also works with PHP if I set
sendmail_path to "/usr/sbin/sendmail cahagn_o@epita.fr"
I found this having a look at my send_mail shell script :
---- snip send.sh ----
ECHO=/bin/echo
OUTFILE=/tmp/mail.test
make_outfile()
{
${ECHO} "Subject: test" >> ${OUTFILE}
${ECHO} "To: cahagn_o@epita.fr" >> ${OUTFILE}
${ECHO} "" >> ${OUTFILE}
${ECHO} "body" >> ${OUTFILE}
${ECHO} "" >> ${OUTFILE}
}
make_outfile;
/usr/sbin/sendmail $(recipient) < ${OUTFILE}
---- snip send.sh ----
(The $(recipient) was filled with the address)
What's wrong with this ? Does it come from /etc/sendmail.cf or an old
version of sendmail (I don't know how to determine the version) ?
Is this the standard way to handle sending mail with sendmail ? What can
I do to have PHP mail() work ?
--
Olivier Cahagne
snina@ambafrance.org
olivier.cahagne@epita.fr