Though I can't be sure (You're question was a bit garbled), it sounds to me you want something like this:
#!/usr/bin/perl -wT eval 'exec perl -wT -S $0 ${1+"$@"}' if 0; # not running under some shell require 5; use strict; use CGI; use URI::URL; use Mail::Mailer; use vars qw( @errors ); my $subject = "Automated Message From $0"; my $mailtext; my $forwardurl = '/thankyou.html'; my $query = new CGI; my @params = $query->param; my $email = $query->param('email'); my $mailto = $query->param('mailto'); # check email address is valid checkemail($email) if $email; # construct the message for whoever's being sent the form my $param; my $value; my @values; foreach $param(@params) { @values = $query->param($param); if ($query->param('other_'.$param)) { foreach $value (@values) { if ($value eq 'other') { push (@values, $query->param('other_'.$param)); last; } } } @values = grep { $_ ne 'other' } @values; ($value = join(', ', @values)) && ($mailtext .= "\u\L$param\E: $valu +e\n"); } if (@errors) { $mailtext .= 'IMPORTANT! The following error'. (@errors>1 ? 's were' + : ' was') ." encountered during execution:\n". join("\n",@errors). " +\n\n"; } sendmail($email, $mailto, $subject, $mailtext); # send off the mail print "Location: $forwardurl\n\n"; # forward the user to + a 'thank you' page exit; sub sendmail { my ($from, $to, $subject, $body) = @_; my $mailer; eval { $mailer = Mail::Mailer->new('sendmail'); }; if ($@) { push (@errors, "Couldn't send mail: $@"); return 0; } else { $mailer->open({ From => $from, To => $to, Subject => $subject }); print $mailer $body; if (close ($mailer)) { return 1; } else { push (@errors, "Couldn't close mailer: $!"); return 0; } } } sub checkemail{ my $addr = shift; my $validmail; return 0 unless eval { unless ($validmail = Email::Valid->address( -address => $addr, -mxcheck => 1 )) { push (@errors, "address failed $Email::Valid::Details check."); if ($Email::Valid::Details eq 'rfc822') { push (@errors, "$addr is unlikely to be a valid email address" +); } elsif ($Email::Valid::Details eq 'mx') { (my $domain = $addr) =~ s/^[^\@]+\@//; push (@errors, "$domain does not seem to have a mailserver"); } return 0; } }; if ($@) { push (@errors, "An error was encountered: $@"); return 0; } return 1; }
This script will mail all the data in the form to the address given in the form field 'mailto'. If you want the address mailed to to be fixed, simply set $mailto to that address.
Hope this helps ;-)

In reply to Re: how do i send an email to someone specified by the user? by kilinrax
in thread how do i send an email to someone specified by the user? by paav1

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.