sending mail with a script question

Ken McGlothlen mcglk at
Sat Apr 5 10:58:49 PST 2003

David Banning <david at> writes:

| I am running a php program in a browser which eventually compiles some files
| and emails them to a person of their choosing. The problem is that the system
| identifies the browser user as nobody.
| I send the mail using a line something like;
| cat textfile | mutt -s"Quote/Attachments" -afile1 -afile2 john at
| but the problem is that the recipient sees the sender address as from
| "nobody at", when I want it seen as "david at".  I have the
| name of the user available in the script but I see no way of running the mail
| script as that person since any browser viewing the system is "nobody".

Well, mutt is moderately inappropriate for this purpose.  On the other hand,
you're also including attachments, which is another problem.

If I recall correctly, PHP has a mail command that you may want to check into.
However, a very simple way of doing it is to use sendmail.  That's what it's
designed for.  Your textfile would have to contain the headers:

        From: david at
        Subject: Quote/Attachments

        [contents of textfile]

or you could use

        cat headers textfile | sendmail john at

Remember, though, that there MUST BE A BLANK LINE between the headers and the
message.  Just make sure the headers file has a blank line at the end.

The MIME attachments are another deal.  For this, you might want to do

        # portinstall mpack

mpack is a MIME packing program (it can also send mail, but not with a
different From address, so we'll leave that out for now).  You'd use it like

        /usr/local/bin/mpack -o /tmp/textfile.$$ bodytext file1 file2
        /bin/cat headerfile /tmp/textfile.$$ | /usr/sbin/sendmail john at
        /bin/rm textfile.$$

(Note that I'm using explicit paths as a small increase in security.)

Hope that helps.

More information about the freebsd-questions mailing list