Sendmail works from script, but not when called from Apache

Hi,

I am building a web interface to run a series of shell scripts that reside on the web server. The bash script are written such that they can be used independently for the task they are meant for, or the same scripts can be run from this web UI. The scripts are mostly for doing software builds, testing, and uploading to another server. The webpage issues a call out to a tiny PHP script that calls the bash shell script. In one of the scripts I am trying to add the ability to send an e-mail with sendmail when a software build fails. It looks something like this:

---------------------------------------------------------------------------------------

DistributionList="me@mydomain.com";
MessageFile="/tmp/build_failure_email.txt";

if [ -e $MessageFile ];
then
    rm $MessageFile
fi
 
#echo "To: $DistributionList" >> $MessageFile;
 
Subject="My Subject...";
echo "Subject: ${Subject}" >> $MessageFile;
 
FromName="My Name";
FromAddress="me@mydomain.com";
echo "From: $FromName <${FromAddress}>" >> $MessageFile;
 
 echo "Message Body line 1..." >> $MessageFile;
echo "Message Body line 2." >> $MessageFile;
 
/usr/sbin/sendmail "$DistributionList" < $MessageFile
#/usr/sbin/sendmail -t "$DistributionList" < $MessageFile

---------------------------------------------------------------------------------------

When I run this script from the command line it works perfectly fine! No errors, and I get the e-mail, all is good in the world.

Now when I invoke the SAME script file via the web UI it produces the following error:

"SendMail: fatal: Recipient addresses must be specified on the command line or via the -t option"

As you can see I AM specifying the address on the command line, and I have also tried it with -t and putting the address in the file. But neither way works when the bash script is called from apache by way of the PHP script. I have spent hours trying to figure this out with no luck. Note, this is all running on Mac OS X. Can anyone provide any assistance, or pointers to relevant informaion?

Note, when I run the script manually from a Terminal window (when it works) I am logged in as an administrative user (not root), call it user_a. Apache is set in its config file to also run as the same administrative (non-root) user, user_a. (And yes I confirmed it is indeed running as that user.) The sendmail command is just a line in the bash script so it should be running as the same user that invokes the script - that would be the user apache is running as - or user_a.

Also, when googling this error it turns up a lot of pages about PHP & Drupal and setting the PHP.ini file to use the -t flag when calling sendmail. But that has nothing to do with my problem. My call to sendmail is not occurring from inside PHP, to be clear, it is inside a bash script that gets called by PHP.

Any help would be greatly appreciated.

THANKS!

MacQAGuy

All,

I hate to admit it, but this was actually something really simple.

I had the portion of the script that sent the e-mail in a separate file, that was (supposed to be) sourced at the top of the main script. When I was running the main script interactively from the command line (when everything worked) it worked because I had already manually sourced that other file earlier in the Terminal session. And when apache was calling that other file it didn't work because that file hadn't been sourced yet. The reason it showed up as a sendmail error message was because in that other file I had named the routine that sent the e-mail "SendMail" as opposed to "sendmail" but when that other file wasn't sourced it was calling the normal sendmail program with no parameters -- thus the error.

Multiple mistakes here: 1) naming the separate routine "SendMail" rather than something more unique, 2) not sourcing the other file at the top of the main file.