#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    2
    Rep Power
    0
    Just I need to know how the following code works.AS I am in the initial stage of learning Perl, I need your help for this.
    I know that this code is for sending mail with the contnts taken from two text areas.
    I need more expanation on it Please...


    #!/usr/bin/perl

    use CGI;
    $query = new CGI;

    $first_textarea_data = $query->param('textarea_a');
    $second_textarea_data = $query->param('textarea_b');

    $mailer = "/path/to/sendmail";

    unless(open(MAIL, "|$mailer -t")) {
    print "Unable to open sendmail at: $mailernn";
    exit;
    }

    print MAIL "TO: recipient@some.comn";
    print MAIL "SUBJECT: This is some fine mail!n";
    print MAIL "FROM: you@your.comnn";

    print MAIL $first_textarea_data;
    print MAIL $second_textarea_data;

    close(MAIL);

  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    4
    Rep Power
    0
    I'm absolutly not a perl expert myself, but my the code means something like:

    "#!/usr/bin/perl"
    Specify where perl is located on your server

    "use CGI;
    $query = new CGI;

    $first_textarea_data = $query->param('textarea_a');
    $second_textarea_data = $query->param('textarea_b');"
    The information that is posted from a HTML-page is transferd into variables. (the HTML-code should be something like:
    <html>
    <form action="blah.pl" method="post">
    <textarea name="textarea_a"></textarea>
    <textarea name="textarea_b"></textarea>
    </form>
    </html> )
    The text entered in the textarea_a is saved into $first_textarea_data, and the text entered in textarea_b is saved into $second_textarea_data.

    '$mailer = "/path/to/sendmail";'
    Specify where sendmail is located on your server.

    'unless(open(MAIL, "|$mailer -t")) {
    print "Unable to open sendmail at: $mailernn";
    exit;
    }'

    Open the mailer specified in $mailer (above) as MAIL.
    If the opening fails a errormessage is viewed for the user.

    'print MAIL "TO: recipient@some.comn";
    print MAIL "SUBJECT: This is some fine mail!n";
    print MAIL "FROM: you@your.comnn";'
    Writes some thing into the mailer opened as MAIL.
    This is the mails header (to, from, subject). After the header you need to n's.

    "print MAIL $first_textarea_data;
    print MAIL $second_textarea_data;"
    Writes the content in the variables into the mailer (opened as MAIL).

    "close(MAIL);"
    Close the mailer.


    As I wrote at the top of the message I'm not an expert, but I hope you know a little bit more. Otherwise I'm sure someoneelse here can tell you more about the script.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    0
    Rep Power
    0
    This code simple takes the input from the user in two fields(textarea_a,text_area_b) in
    an html form and emails and constructs the body of the email and then send it to the intended party.

    At the begining, it checks to see if sendmail daemon is up and running on the box before trying to sewnd the email and if not, it prints out an error message saying so to the user.

    Hope taht helps.

IMN logo majestic logo threadwatch logo seochat tools logo