http://qs1969.pair.com?node_id=43213


in reply to email submission

Check that 'www-data' (or whichever user is sending the mail) is allowed by your MTA to set the 'From:' field. For instance, if you're using exim, add the user name to the 'trusted users' field of '/etc/exim.conf', e.g:
trusted_users = mail:www-data
If you're not using exim, then I'm sorry I can't be more help, but there will probably be a similar configuration option somewhere, which I'd guess should be covered in the documentation of whatever you're using ;-)

Update: Thought you might find the following code useful to check yours against or even adapt to your purposes ;-)
#!/usr/bin/perl -w use strict; use Mail::Mailer; use Getopt::Std; use vars qw( %opts $line $user $body ); getopts('f:t:s:h', \%opts); $user = getpwuid($<); sub usage() { print <<EOF; Usage: $0 [options] Example: $0 -t root\@jerkcity.com -f die.puny\@earthling.net -s \'Your + comic is the wierdest thing _ever_\' Synopsis: sends mail to the specified address -h : displays this help screen -t ADDRESS : address to mail to -f ADDRESS : address to mail from (default is your user name: \'$user\ +') -s SUBJECT : subject of the mail If no flags are given, then the first argument given is assumed to be +the address to mail to, or if no options are given, this help screen +is displayed. EOF exit; } if ($opts{'h'}) { usage(); } if (!$opts{'t'}) { if ($ARGV[0]) { $opts{'t'} = $ARGV[0]; } else { die "You must enter an address to mail to. See $0 -h for help on u +sage."; } } if (!$opts{'f'}) { $opts{'f'} = $user; } if (!$opts{'s'}) { $opts{'s'} = 'No subject'; } print "Enter body of message, use a single \'.\' on a line to finish.\ +n"; while ($line = <STDIN>) { last if ($line =~ /^\.$/); $body .= $line; } sendmail ($opts{'f'}, $opts{'t'}, $opts{'s'}, $body); print "Mail Sent.\n"; exit; sub sendmail { my ($from, $to, $subject, $body) = @_; my $mailer; eval { $mailer = Mail::Mailer->new('sendmail'); }; if ($@) { warn "Couldn't send mail: $@"; } else { $mailer->open({ To => $to, From => $from, Subject => $subject }); print $mailer $body; unless (close ($mailer)) { warn "Couldn't close mailer: $!"; } } }