Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Form Mailer

by vroom (His Eminence)
on Jan 28, 2000 at 01:14 UTC ( [id://2515]=sourcecode: print w/replies, xml ) Need Help??
Category: E-mail
Author/Contact Info vroom vroom@cs.hope.edu
Description:
An old script I wrote about a year ago.  
Not very elegant but gets the job done.
Sending out seemingly personalized letters to a list of people.

It takes a couple of files:
   A data file that looks like:

EMAIL|REALNAME
bob@blah.com|Bob Blah
george@blah.com|George Blah

It needs an EMAIL column so it knows where to send the mail to
the rest of the columns are up to you.  Column headers and row
data are separated by |'s

Then you just make a message file like so and it makes the
necessary substitutions:

Dear REALNAME,
Your e-mail address is: EMAIL

Love,

Your Mom
#!/usr/bin/perl
print "Form Mailer 0.1\n";
print "Where's your data file?\n";
$datafile=<>;
print "What's the subject of your message?\n";
$subject=<>;
print "Who do you want the message to be from? (your e-mail)\n";
$from=<>;
print "Where's the message located?\n";
$messageloc= <>;
chomp($from,$messageloc,$datafile);
open MESSAGE,"<$messageloc";
$messagebody=join '', <MESSAGE>;
close MESSAGE;
open DATA, "<$datafile";
$header=<DATA>;
chomp $header;
@header=split(/\|/,$header);
while($line=<DATA>){
    chomp $line;
   @linesplit=split(/\|/,$line);
    for(my $i=0; $i<@header; $i++){
        $header{$header[$i]}=$linesplit[$i];
    }
    $message=$messagebody;
    foreach(keys %header){
        print "key $_ => $header{$_}\n";
        $message=~s/$_/$header{$_}/g;
    }
    open(MAIL, "|/usr/lib/sendmail -oem -t -oi");
    print MAIL "From: $from\n";
    print MAIL "To: $header{EMAIL}\n";
    print MAIL "Subject: $subject\n\n";
    print MAIL "$message\n";
    close MAIL;
}
close DATA;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://2515]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-18 12:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found