this is a script i have that sends an email to a list of people. what i need to know is the easiest and best way to grep the users IP address and insert it into the headers of the outgoing email. thanks for any help.
#!/usr/local/bin/perl use CGI; $foo = new CGI; $recips = $foo->param('recipient'); $realname = $foo->param('realname'); $realemail = $foo->param('realemail'); $mailprog = '/usr/sbin/sendmail'; @recipients = split("\, ", $recips); if(defined ($val = $foo->cookie(-name => "sent-mail"))) { print $foo->header(); print " <body bgcolor=\"#FFCC00\"> <p align=\"center\"><big><big><strong><font face=\"Arial\">Sorry $real +name, emails can only be sent once.</font></strong></big></big></p> </body>"; } else { foreach $person (@recipients) { ($pname, $pemail) = split("\<", $person); $pemail =~ s/\>.*//; $pname =~ s/\s+//; open(MAIL,"|$mailprog -t"); print MAIL "To: $pemail\n"; print MAIL "From: $realemail ($realname)\n"; print MAIL "Subject: $pname, interesting site\n\n"; print MAIL " $pname message....... $realname"; close (MAIL); } open(FILE, ">> addresses.txt"); @addresses = <FILE>; foreach $person (@recipients) { ($pname, $pemail) = split("\<", $person); $pemail =~ s/\>//; if($pemail !=~ /\s+\,\s+/) { print FILE "$pemail\n"; }} close(FILE); print $foo->header(); $cookie = $foo->cookie('-name' => "sent-mail", '-value' => "sent"); print " <body bgcolor=\"#FFCC00\"> <script language=javascript> alert(\"Thank you\"); </script> </body>"; }

In reply to IP and mail header by nujersedvl

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.