I'm trying to create a cgi script that will send mail to a certain address, appearing to be from another address (one a user types into a form).
I can do this using sendmail thusly:
sendmail ('god@heaven.com', 'die.puny@earthling.net', 'Test', 'This is + a test'); sub sendmail { my ($from, $to, $subject, $body) = @_; open(MAIL, "|/usr/lib/sendmail -oem -t -oi -f $from"); print MAIL "To: $to\n"; print MAIL "Subject: $subject\n\n"; print MAIL "$body\n"; close MAIL; }
Which works fine. However, attempting to do this with Mail::Mailer, results in the mail appearing to come from www-data.
sendmail ('god@heaven.com', 'die.puny@earthling.net', 'Test', 'This is + a test'); sub sendmail { my ($from, $to, $subject, $body) = @_; my $mailer; eval { $mailer = Mail::Mailer->new(); }; if ($@) { warn "Couldn't send mail: $@"; } else { $mailer->open({ From => $from, To => $to, Subject => $subject }); print $mailer $body; unless (close ($mailer)) { warn "Couldn't close mailer: $!"; } } }
I've read all the documentation I've been able to lay my hands on (Mail::Mailer's is rather minimal), and done a Super Search, but all to no avail.
So, fellow monks, is there any way of forcing the 'From:' field using Mail::Mailer?

[Btw, I'm using exim as my MTA, and www-data is listed in trusted_users]

In reply to Changing the 'From:' header with Mail::Mailer by kilinrax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.