Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a mail script created for use from command line.
I want create a simple html web interface to use this script as remotely hosted script, from webhost.
The script contains two files- Data File.dat(which holds the list of email addresses, where the mail has to be sent;
the addresses are separated by new lines); and Message template File.template(this file contains the message template to be sent.)
Need some help with code, if possible.
Thanks.

#!/usr/bin/perl -w #user configuration begin# $mailprg = "/usr/sbin/sendmail"; #path to your mail program $delay = 0.25; #delay in seconds $from = 'Coname<somename@domain.com>'; #from address in your m +ail $subject = 'Trial send'; #subject of newsletter. u can add + the spl code $USERNAME$ $maildata = "mail.dat"; #mail address file $msgtemplate = "message.template"; #message template file #user configuration end# if(@ARGV){ $i = 0; while($ARGV[$i]){ if($ARGV[$i] eq "--help"){ print "Command Line Options:\n\n"; print "-t\tTest how the message will be formatted\n"; print "-d\tData file listing the email addresses\n"; print "-m\tMessage template file\n"; print "-s\tSubject\n"; print "-f\tFrom address. Quote for security reasons\n"; die "\nMore information at indiWiz.com\n"; } elsif($ARGV[$i]=~/^-/){ $arr = substr($ARGV[$i],1,1); if($arr eq "d"){ $maildata = $ARGV[$i+1]; $i+=2; } elsif($arr eq "m"){ $msgtemplate = $ARGV[$i+1]; $i+=2; } elsif($arr eq "t"){ $testflag = 1; $i++; } elsif($arr eq "s"){ $subject = $ARGV[$i+1]; $i+=2; } elsif($arr eq "f"){ $from = $ARGV[$i+1]; $i+=2; } else{ die "Wrong argument!"; } } } } open TEMPLATE, $msgtemplate || die "Cannot open template file!\n"; while(<TEMPLATE>){ $msg .= $_; } close TEMPLATE || die "Cannot close template file!\n"; open MAILFILE,"$maildata" || die "Cannot open data file!\n"; while(<MAILFILE>){ chomp($_); @arr = split(/\@/,$_); $arr[0] = ucfirst($arr[0]); $tmp = $msg; $tmp =~ s/\$USERNAME\$/$arr[0]/g; $subject =~ s/\$USERNAME\$/$arr[0]/g; $temp = "To: $arr[0]<$_>\n"; $temp .= "From: $from\n"; $temp .= "Subject: $subject\n\n\n"; $temp .= $tmp; if($testflag){ print $temp; last; } else{ open MAILPRG,"|$mailprg -t" || die "Cannot open mail program!\ +n"; print MAILPRG $temp; close MAILPRG || die "Cannot close mailprogram!\n"; if($delay < 0){ $delay = 1; sleep $delay; } elsif($delay < 1){ select(undef,undef,undef,$delay); } else{ sleep $delay; } print $_,"\n"; } } close MAILFILE || die "Cannot close data file!\n";

Janitored by Arunbear - added readmore tags, as per Monastery guidelines

Replies are listed 'Best First'.
Re: Simple web interface for simple script
by dragonchild (Archbishop) on Apr 25, 2005 at 13:17 UTC
    What's the problem? What have you tried? How has that failed? Have you designed your web interface yet? What about the flow of control? What kind of access controls do you have/want?

    In other words, you have an idea of what you want, but I don't think you've really worked out how you're going to get there. Now, you may not know how to get there, and that's fine. But, I'm not going to write your code for you. A web script is a completely different beast than a commandline script, even if they share 90% of the same code.


    The Perfect is the Enemy of the Good.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Simple web interface for simple script
by ChrisR (Hermit) on Apr 25, 2005 at 13:32 UTC
    First things first:
    use strict;
    Secondly, you might try looking at the CGI module to get an idea of how many people do it.
    A reply falls below the community's threshold of quality. You may see it by logging in.