Email Article to friend - PART TWO (!)
Posted on 2000-04-12
Hello everyone. The following is the code provided to my earlier CGI question. It works fine. But I would like to know if insteasd of embedding the text file which is to be emailed to the recipient within the cgi file, if the file name could be included in the text submit form on the HTML page. (The file name that I would like to keep in the form -- in a hidden field (and not in the cgi bin is "/mnt/web/guide/mdsutton/cgibin/email_articles/test-article.txt")
That way I could keep one emailing program in my cgi bin and not have to modify it every time I add a new text file to be emailed. This particular web site will be adding emailed articles every few days and I'd rather not have to create a new CGI file for every article.
Again, here is the script by which works nicely.
$articlename = "I asked M.D. Sutton to send you this Informative article";
#The article name can be passed as hidden field.
$filePath = "/mnt/web/guide/mdsutton/cgibin/email_articles/test-article.txt";
# the absolute path to the file.
open (FILE, $filePath) || die "cant open $filePath...$!";
$articlebody .= $_;
$mail_program = "/usr/sbin/sendmail -t";
open (MAIL, "|$mail_program") || die ("Could Not Open Mail Program");
print MAIL "To: $friendname <$friendmail>\n";
print MAIL "From: $sendername <$sendermail>\n";
print MAIL "Subject: $articlename\n\n";
print MAIL $articlebody;
print "Content-type: text/html\n\n";
open (HTML_FILE, "/mnt/web/guide/mdsutton/cgibin/email_articles/success_msg.html") || die "cant open the html file";
@Success_Html = <HTML_FILE>;